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
- Self type
-
BodyCache.type
Members list
In this article