api

http4k / org.http4k.filter / ServerFilters

ServerFilters

object ServerFilters (source)

Types

Name Summary
BasicAuth object BasicAuth
Simple Basic Auth credential checking.
BearerAuth object BearerAuth
Bearer Auth token checking.
CatchAll object CatchAll
Last gasp filter which catches all exceptions and returns a formatted Internal Server Error.
CatchLensFailure object CatchLensFailure : Filter
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.
CopyHeaders object CopyHeaders
Copy headers from the incoming request to the outbound response.
Cors object Cors
Add Cors headers to the Response, according to the passed CorsPolicy
GZip object GZip
Basic GZip and Gunzip support of Request/Response. Does not currently support GZipping streams. Only Gunzips requests which contain “transfer-encoding” header containing ‘gzip’ Only Gzips responses when request contains “accept-encoding” header containing ‘gzip’.
GZipContentTypes class GZipContentTypes : Filter
Basic GZip and Gunzip support of Request/Response where the content-type is in the allowed list. Does not currently support GZipping streams. 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.
InitialiseRequestContext object InitialiseRequestContext
Initialise a RequestContext for each request which passes through the Filter stack,
ReplaceResponseContentsWithStaticFile object 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.
RequestTracing object RequestTracing
Adds Zipkin request tracing headers to the incoming request and outbound response. (traceid, spanid, parentspanid)
SetContentType object SetContentType
Sets the Content Type response header on the Response.

Functions

| Name | Summary | |—|—| | CatchLensFailure | fun CatchLensFailure(failResponseFn: (LensFailure) -> Response = { Response(BAD_REQUEST.description(it.failures.joinToString("; "))) }): Filter
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. |

Extension Functions

Name Summary
HandleUpstreamRequestFailed fun ServerFilters.HandleUpstreamRequestFailed(exceptionToBody: UpstreamRequestFailed.() -> String = { localizedMessage }): Filter
Handle exceptions from upstream calls and convert them into sensible server-side errors. Optionally pass in a function to format the response body from the exception.
ProcessFiles fun ServerFilters.ProcessFiles(fileConsumer: (MultipartEntity.File) -> String): Filter
Process files on upload using the passed consumer, which returns a reference. The form file is replaced in the form with this reference.
with fun <T> T.with(vararg modifiers: (T) -> T): T