From e0145f71f12e1732491f420d076f0d76a93f28f7 Mon Sep 17 00:00:00 2001 From: Piotr Limanowski Date: Tue, 17 Sep 2024 18:57:34 +0200 Subject: [PATCH] Remove timeout middleware --- .../HttpServer.scala | 17 ++---- .../HttpServerSpec.scala | 52 ------------------- 2 files changed, 3 insertions(+), 66 deletions(-) delete mode 100644 core/src/test/scala/com.snowplowanalytics.snowplow.collector.core/HttpServerSpec.scala diff --git a/core/src/main/scala/com.snowplowanalytics.snowplow.collector.core/HttpServer.scala b/core/src/main/scala/com.snowplowanalytics.snowplow.collector.core/HttpServer.scala index b0d30c424..fe9cb9f7d 100644 --- a/core/src/main/scala/com.snowplowanalytics.snowplow.collector.core/HttpServer.scala +++ b/core/src/main/scala/com.snowplowanalytics.snowplow.collector.core/HttpServer.scala @@ -19,15 +19,13 @@ import org.http4s.{HttpApp, HttpRoutes} import org.http4s.blaze.server.BlazeServerBuilder import org.http4s.headers.`Strict-Transport-Security` import org.http4s.server.Server -import org.http4s.server.middleware.{HSTS, Logger => LoggerMiddleware, Metrics, Timeout} +import org.http4s.server.middleware.{HSTS, Logger => LoggerMiddleware, Metrics} import org.typelevel.ci.CIString import org.typelevel.log4cats.Logger import org.typelevel.log4cats.slf4j.Slf4jLogger import java.net.InetSocketAddress import javax.net.ssl.SSLContext -import org.http4s.Response -import org.http4s.Status object HttpServer { @@ -47,7 +45,7 @@ object HttpServer { ): Resource[F, Server] = for { withMetricsMiddleware <- createMetricsMiddleware(routes, metricsConfig) - httpApp <- Resource.pure(httpApp(withMetricsMiddleware, healthRoutes, hsts, networking, debugHttp)) + httpApp <- Resource.pure(httpApp(withMetricsMiddleware, healthRoutes, hsts, debugHttp)) server <- mkServer(httpApp, port, secure, networking) } yield server @@ -63,7 +61,6 @@ object HttpServer { .withHttpApp(httpApp) .withIdleTimeout(networking.idleTimeout) .withMaxConnections(networking.maxConnections) - .withResponseHeaderTimeout(networking.responseHeaderTimeout) .withLengthLimits( maxRequestLineLen = networking.maxRequestLineLength, maxHeadersLen = networking.maxHeadersLength @@ -75,11 +72,10 @@ object HttpServer { routes: HttpRoutes[F], healthRoutes: HttpRoutes[F], hsts: Config.HSTS, - networking: Config.Networking, debugHttp: Config.Debug.Http ): HttpApp[F] = hstsApp( hsts, - loggerMiddleware(timeoutMiddleware(routes, networking) <+> healthRoutes, debugHttp) + loggerMiddleware(routes <+> healthRoutes, debugHttp) ) private def createMetricsMiddleware[F[_]: Async]( @@ -116,13 +112,6 @@ object HttpServer { )(routes) } else routes - private def timeoutMiddleware[F[_]: Async](routes: HttpRoutes[F], networking: Config.Networking): HttpRoutes[F] = - Timeout.httpRoutes[F](timeout = networking.responseHeaderTimeout)(routes).map { - case Response(Status.ServiceUnavailable, httpVersion, headers, body, attributes) => - Response[F](Status.RequestTimeout, httpVersion, headers, body, attributes) - case response => response - } - implicit class ConditionalAction[A](item: A) { def cond(cond: Boolean, action: A => A): A = if (cond) action(item) else item diff --git a/core/src/test/scala/com.snowplowanalytics.snowplow.collector.core/HttpServerSpec.scala b/core/src/test/scala/com.snowplowanalytics.snowplow.collector.core/HttpServerSpec.scala deleted file mode 100644 index dc91f0835..000000000 --- a/core/src/test/scala/com.snowplowanalytics.snowplow.collector.core/HttpServerSpec.scala +++ /dev/null @@ -1,52 +0,0 @@ -package com.snowplowanalytics.snowplow.collector.core - -import org.specs2.mutable.Specification -import cats.effect.IO - -import org.http4s.client.Client -import org.http4s._ -import org.http4s.dsl.io._ -import org.http4s.implicits._ -import scala.concurrent.duration._ -import cats.effect.testing.specs2._ - -class HttpServerSpec extends Specification with CatsEffect { - val routes = HttpRoutes.of[IO] { - case _ -> Root / "fast" => - Ok("Fast") - case _ -> Root / "never" => - IO.never[Response[IO]] - } - val healthRoutes = HttpRoutes.of[IO] { - case _ -> Root / "health" => - Ok("ok") - } - - "HttpServer" should { - "manage request timeout" should { - "timeout threshold is configured" in { - val config = - TestUtils - .testConfig - .copy(networking = TestUtils.testConfig.networking.copy(responseHeaderTimeout = 100.millis)) - val httpApp = HttpServer.httpApp( - routes, - healthRoutes, - config.hsts, - config.networking, - config.debug.http - ) - val client: Client[IO] = Client.fromHttpApp(httpApp) - val request: Request[IO] = Request(method = Method.GET, uri = uri"/never") - val res: IO[String] = client.expect[String](request) - - res - .attempt - .map(_ must beLeft[Throwable].which { - case org.http4s.client.UnexpectedStatus(Status.RequestTimeout, _, _) => true - case _ => false - }) - } - } - } -}