object BracketRequestResponse
Middelwares which allow for bracketing on a Request/Response, including the completion of the Response body stream.
These are analogous to cats.effect.Bracket and fs2.Stream.bracket. The
reason that they exist is because due to the full termination of a
Response being a function of the termination of the fs2.Stream which
backs the response body, you can't actually use either
cats.effect.Bracket or fs2.Stream.bracket directly.
- Alphabetic
- By Inheritance
- BracketRequestResponse
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
type
FullContextMiddleware[F[_], A, B] = (Kleisli[[β$0$]OptionT[F, β$0$], ContextRequest[F, A], ContextResponse[F, B]]) ⇒ Kleisli[[β$1$]OptionT[F, β$1$], Request[F], Response[F]]
A Middleware which uses both a ContextRequest and ContextResponse.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
bracketRequestResponseApp[F[_], A](acquire: F[A])(release: (A) ⇒ F[Unit])(implicit F: BracketThrow[F]): (Kleisli[F, ContextRequest[F, A], Response[F]]) ⇒ Kleisli[F, Request[F], Response[F]]
As #bracketRequestResponseCaseApp, but
releaseis simplified, ignoring the exit condition.As #bracketRequestResponseCaseApp, but
releaseis simplified, ignoring the exit condition.- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.
-
def
bracketRequestResponseAppR[F[_], A](resource: Resource[F, A])(implicit F: BracketThrow[F]): (Kleisli[F, ContextRequest[F, A], Response[F]]) ⇒ Kleisli[F, Request[F], Response[F]]
As #bracketRequestResponseApp, but
acquireandreleaseare defined in terms of a cats.effect.Resource.As #bracketRequestResponseApp, but
acquireandreleaseare defined in terms of a cats.effect.Resource.- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.
-
def
bracketRequestResponseCaseApp[F[_], A](acquire: F[A])(release: (A, ExitCase[Throwable]) ⇒ F[Unit])(implicit F: BracketThrow[F]): (Kleisli[F, ContextRequest[F, A], Response[F]]) ⇒ Kleisli[F, Request[F], Response[F]]
As #bracketRequestResponseCaseRoutes but defined for HttpApp, rather than HttpRoutes.
As #bracketRequestResponseCaseRoutes but defined for HttpApp, rather than HttpRoutes.
- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.
-
def
bracketRequestResponseCaseRoutes[F[_], A](acquire: F[A])(release: (A, ExitCase[Throwable]) ⇒ F[Unit])(implicit F: BracketThrow[F]): ContextMiddleware[F, A]
Bracket on the start of a request and the completion of processing the response body Stream.
Bracket on the start of a request and the completion of processing the response body Stream.
- acquire
Effect to run each time a request is received. The result of it is put into a
ContextRequestand passed to the underlying routes.- release
Effect to run at the termination of each response body, or on any error after
acquirehas run. Will always be called exactly once ifacquireis invoked, for each request/response.
- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
,releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.A careful reader might be wondering where the analogous
useparameter fromcats.effect.Brackethas gone. The use of the acquired resource is running the request, thus theusefunction is actually just the normal context route function from http4sKleisli[OptionT[F, *], ContextRequest[F, A], Response[F]].
-
def
bracketRequestResponseCaseRoutes_[F[_], A, B](acquire: (Request[F]) ⇒ F[ContextRequest[F, A]])(release: (A, Option[B], ExitCase[Throwable]) ⇒ F[Unit])(implicit F: BracketThrow[F]): FullContextMiddleware[F, A, B]
Bracket on the start of a request and the completion of processing the response body Stream.
Bracket on the start of a request and the completion of processing the response body Stream.
This middleware uses a context on both the Request and Response. This is the most general possible encoding for bracketing on a Request/Response interaction. It is required to express certain types of bracketing use cases (see Metrics), but for most cases it is more general than is needed. Before attempting to use this middleware, you should consider if #bracketRequestResponseRoutes or #bracketRequestResponseCaseRoutes will work for your use case.
- acquire
Function of the Request to a
F[ContextRequest]to run each time a new Request is received.- release
Function to run on the termination of a Request/Response interaction, in all cases. The first argument is the request context, which is guaranteed to exist if acquire succeeds. The second argument is the response context, which will only exist if the generation of the
ContextResponseis successful. The third argument is the exit condition, either completed, canceled, or error.
- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
,releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.For some use cases, you might want to differentiate between each of the three exit branches where
,releasemay be invoked. The three exit branches are, running a Request and receivingOptionT.none[F, Response[F]], running a Request and encountering an error or cancellation before the Response is generated, or at the full consumption of the Response body stream (regardless of theExitCase). One may determine the in which branchreleaseis being invoked by inspecting theExitCaseand theOption[B]response context. If the response context is defined, e.g.Some(_: B), then you can be certain that thereleasefunction was executed at the termination of the body stream. This is because the response context is only (and always) present if the Response value was generated successfully (whether or not the body stream fails). If theExitCaseisCompletedand the response context isNone, then that means that the underlying HttpRoutes did not yield a Response, e.g. we gotOptionT.none: OptionT[F, Response[F]]. Otherwise, if theExitCaseis eitherError(_: Throwable)orCanceled, and the response context isNone, thenreleaseis executed in response to an error or cancellation during the generation of the Response value proper, e.g. when running the underlyingHttpRoutes.A careful reader might be wondering where the analogous
useparameter fromcats.effect.Brackethas gone. The use of the acquired resource is running the request, thus theusefunction is actually just the normal context route function from http4sKleisli[OptionT[F, *], ContextRequest[F, A], Response[F]].
-
def
bracketRequestResponseRoutes[F[_], A](acquire: F[A])(release: (A) ⇒ F[Unit])(implicit F: BracketThrow[F]): ContextMiddleware[F, A]
As #bracketRequestResponseCaseRoutes, but
releaseis simplified, ignoring the exit condition.As #bracketRequestResponseCaseRoutes, but
releaseis simplified, ignoring the exit condition.- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.
-
def
bracketRequestResponseRoutesR[F[_], A](resource: Resource[F, A])(implicit F: BracketThrow[F]): ContextMiddleware[F, A]
As #bracketRequestResponseRoutes, but
acquireandreleaseare defined in terms of a cats.effect.Resource.As #bracketRequestResponseRoutes, but
acquireandreleaseare defined in terms of a cats.effect.Resource.- Note
The bracketing semantics defined here differ in one very important way from cats-effect or fs2 bracketing semantics. If the Response body is not evaluated after the application of the middleware, then the
releasehandler will not run, effectively creating a resource leak. This can happen due to a bug in a server implementation, where it fails to drain the body, or due to a user code if the Response body stream (or the Response itself) is discarded after the application of this middleware. Unfortunately, there is currently no way to avoid this. For this reason, it is strongly recommended that this middleware be applied at the most outer scope possible. Appending to or transforming the Response body is safe to do after the application of this middleware.
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()