BodyCache

object BodyCache

Middleware for caching the request body for multiple compilations

As the body of the request is the Stream of bytes, compiling it several times (e.g. with middlewares) is unsafe. This middleware forbids such behaviour, compiling the body only once. It does so only for the "inner" middlewares:

val route = AMiddleware(BodyCache(SomeOtherMiddleware(myRoute)))

In this example only myRoute & SomeOtherMiddleware will receive cached request body, while the AMiddleware will get the raw one.

As the entire request body will be allocated in memory, there is a possibility of OOM error with a large body. Because of that, using the EntityLimiter middleware is strongly advised.

Note

This middleware has nothing to do with the HTTP caching mechanism and it does not cache bodies between multiple requests.

class Object
trait Matchable
class Any

Value members

Concrete methods

def apply[G[_] : Concurrent, F[_] : Concurrent, R](old: Kleisli[G, R, Response[F]])(reqGet: R => Request[F], reqSet: R => Request[F] => R)(lift: FunctionK[F, G]): Kleisli[G, R, Response[F]]
def contextRoutes[T, F[_] : Concurrent](routes: ContextRoutes[T, F]): ContextRoutes[T, F]
def hasNoBody[F[_]](req: Request[F]): Boolean
def httpApp[F[_] : Concurrent](app: HttpApp[F]): HttpApp[F]
def httpRoutes[F[_] : Concurrent](routes: HttpRoutes[F]): HttpRoutes[F]