Skip to content

Commit

Permalink
Remove debug http
Browse files Browse the repository at this point in the history
  • Loading branch information
peel committed Sep 20, 2024
1 parent 2375edf commit cffa643
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ 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.typelevel.ci.CIString
import org.http4s.server.middleware.{HSTS, Metrics, Timeout}
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger

Expand All @@ -40,14 +39,13 @@ object HttpServer {
secure: Boolean,
hsts: Config.HSTS,
networking: Config.Networking,
metricsConfig: Config.Metrics,
debugHttp: Config.Debug.Http
metricsConfig: Config.Metrics
)(
mkServer: ((HttpApp[F], Int, Boolean, Config.Networking) => Resource[F, Server])
): Resource[F, Server] =
for {
withMetricsMiddleware <- createMetricsMiddleware(routes, metricsConfig)
httpApp <- Resource.pure(httpApp(withMetricsMiddleware, healthRoutes, hsts, networking, debugHttp))
httpApp <- Resource.pure(httpApp(withMetricsMiddleware, healthRoutes, hsts, networking))
server <- mkServer(httpApp, port, secure, networking)
} yield server

Expand Down Expand Up @@ -75,11 +73,10 @@ object HttpServer {
routes: HttpRoutes[F],
healthRoutes: HttpRoutes[F],
hsts: Config.HSTS,
networking: Config.Networking,
debugHttp: Config.Debug.Http
networking: Config.Networking
): HttpApp[F] = hstsApp(
hsts,
loggerMiddleware(timeoutMiddleware(routes, networking) <+> healthRoutes, debugHttp)
timeoutMiddleware(routes, networking) <+> healthRoutes
)

private def createMetricsMiddleware[F[_]: Async](
Expand All @@ -106,16 +103,6 @@ object HttpServer {
HSTS(routes.orNotFound, `Strict-Transport-Security`.unsafeFromDuration(hsts.maxAge))
else routes.orNotFound

private def loggerMiddleware[F[_]: Async](routes: HttpRoutes[F], config: Config.Debug.Http): HttpRoutes[F] =
if (config.enable) {
LoggerMiddleware.httpRoutes[F](
logHeaders = config.logHeaders,
logBody = config.logBody,
redactHeadersWhen = config.redactHeaders.map(CIString(_)).contains(_),
logAction = Some((msg: String) => Logger[F].debug(msg))
)(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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ object Run {
config.ssl.enable,
config.hsts,
config.networking,
config.monitoring.metrics,
config.debug.http
config.monitoring.metrics
)(HttpServer.buildBlazeServer)
_ <- withGracefulShutdown(config.preTerminationPeriod)(httpServer)
httpClient <- BlazeClientBuilder[F].resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class HttpServerSpec extends Specification with CatsEffect {
routes,
healthRoutes,
config.hsts,
config.networking,
config.debug.http
config.networking
)
val client: Client[IO] = Client.fromHttpApp(httpApp)
val request: Request[IO] = Request(method = Method.GET, uri = uri"/never")
Expand Down

0 comments on commit cffa643

Please sign in to comment.