BodyCache

org.http4s.server.middleware.BodyCache$
object BodyCache

Middleware for caching the request body for multiple compilations

As the body of the request is the fs2.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.

Attributes

Note:

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

Source:
BodyCache.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Concise view

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]]

Attributes

Source:
BodyCache.scala
def hasNoBody[F[_]](req: Request[F]): Boolean

Attributes

Source:
BodyCache.scala

Attributes

Source:
BodyCache.scala