Skip to content

Commit

Permalink
Merge pull request #40 from NthPortal/expose-generic-server-build
Browse files Browse the repository at this point in the history
Expose method to build generic middleware
  • Loading branch information
NthPortal authored Jan 2, 2024
2 parents 21125a6 + 0a75389 commit b232937
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ object ServerMiddleware {
def withDoNotTrace(doNotTrace: RequestPrelude => Boolean): ServerMiddlewareBuilder[F] =
copy(doNotTrace = doNotTrace)

private def buildTracedF[G[_]: MonadCancelThrow](
/** This method is used for building a middleware in a way that abstracts
* over [[org.http4s.HttpApp `HttpApp`]] and
* [[org.http4s.HttpRoutes `HttpRoutes`]]. In most cases, it is preferable
* to use the methods that directly build the specific desired type.
*
* @see [[buildHttpApp]]
* @see [[buildHttpRoutes]]
*/
def buildGenericTracedHttp[G[_]: MonadCancelThrow](
f: Http[G, F]
)(implicit kt: KindTransformer[F, G]): Http[G, F] =
Kleisli { (req: Request[F]) =>
Expand Down Expand Up @@ -170,10 +178,10 @@ object ServerMiddleware {
}

def buildHttpApp(f: HttpApp[F]): HttpApp[F] =
buildTracedF(f)
buildGenericTracedHttp(f)

def buildHttpRoutes(f: HttpRoutes[F]): HttpRoutes[F] =
buildTracedF(f)
buildGenericTracedHttp(f)
}

private[middleware] def request[F[_]](
Expand Down

0 comments on commit b232937

Please sign in to comment.