http4k / org.http4k.filter / ServerFilters
object ServerFilters
Name | Summary |
---|---|
ApiKeyAuth | ApiKey token checking.object ApiKeyAuth |
BasicAuth | Simple Basic Auth credential checking.object BasicAuth |
BearerAuth | Bearer Auth token checking.object BearerAuth |
CatchAll | Last gasp filter which catches all exceptions and returns a formatted Internal Server Error.object CatchAll |
CatchLensFailure | Converts Lens extraction failures into correct HTTP responses (Bad Requests/UnsupportedMediaType). This is required when using lenses to automatically unmarshall inbound requests. Note that LensFailures from unmarshalling upstream Response objects are NOT caught to avoid incorrect server behaviour.object CatchLensFailure : Filter |
CopyHeaders | Copy headers from the incoming request to the outbound response.object CopyHeaders |
Cors | Add Cors headers to the Response, according to the passed CorsPolicyobject Cors |
GZip | Basic GZip and Gunzip support of Request/Response. Only Gunzips requests which contain “transfer-encoding” header containing ‘gzip’ Only Gzips responses when request contains “accept-encoding” header containing ‘gzip’.object GZip |
GZipContentTypes | Basic GZip and Gunzip support of Request/Response where the content-type is in the allowed list. Only Gunzips requests which contain “transfer-encoding” header containing ‘gzip’ Only Gzips responses when request contains “accept-encoding” header containing ‘gzip’ and the content-type (sans-charset) is one of the compressible types.class GZipContentTypes : Filter |
InitialiseRequestContext | Initialise a RequestContext for each request which passes through the Filter stack,object InitialiseRequestContext |
ReplaceResponseContentsWithStaticFile | Intercepts responses and replaces the contents with contents of the statically loaded resource. By default, this Filter replaces the contents of unsuccessful requests with the contents of a file named after the status code.object ReplaceResponseContentsWithStaticFile |
RequestTracing | Adds Zipkin request tracing headers to the incoming request and outbound response. (traceid, spanid, parentspanid)object RequestTracing |
SetContentType | Sets the Content Type response header on the Response.object SetContentType |
| Name | Summary |
|—|—|
| CatchLensFailure | Converts Lens extraction failures into correct HTTP responses (Bad Requests/UnsupportedMediaType). This is required when using lenses to automatically unmarshall inbound requests. Note that LensFailures from unmarshalling upstream Response objects are NOT caught to avoid incorrect server behaviour.fun CatchLensFailure(failResponseFn: (
LensFailure
) ->
Response
= {
Response(BAD_REQUEST.description(it.failures.joinToString("; ")))
}): <ERROR CLASS>
|
Name | Summary |
---|---|
MicrometerMetrics | val ServerFilters .MicrometerMetrics: MicrometerMetrics |
OpenTelemetryMetrics | val ServerFilters .OpenTelemetryMetrics: OpenTelemetryMetrics |
Name | Summary |
---|---|
HandleRemoteRequestFailed | Handle exceptions from remote calls and convert them into sensible server-side errors. Optionally pass in a function to format the response body from the exception.fun ServerFilters .HandleRemoteRequestFailed(exceptionToBody: RemoteRequestFailed .() -> String = Throwable::getLocalizedMessage): Filter |
OpenTelemetryTracing | fun ServerFilters .OpenTelemetryTracing(tracer: Tracer = Http4kOpenTelemetry.tracer, spanNamer: ( Request ) -> String = { it.uri.toString() }, error: ( Request , Throwable ) -> String = { _, t -> t.localizedMessage }): Filter |
ProcessFiles | Process files on upload using the passed consumer, which returns a reference. The form file is replaced in the form with this reference.fun ServerFilters .ProcessFiles(fileConsumer: (File) -> String ): <ERROR CLASS> |