Protocol
Middleware
public protocol Middleware
Middleware
is placed between the server and your router. It is capable of
mutating both incoming requests and outgoing responses. Middleware
can choose
to pass requests on to the next Middleware
in a chain, or they can short circuit and
return a custom Response
if desired.
Relationships
Types Conforming to Middleware
Authenticator
Helper for creating authentication middleware.
AsyncMiddleware
AsyncMiddleware
is placed between the server and your router. It is capable of mutating both incoming requests and outgoing responses.AsyncMiddleware
can choose to pass requests on to the nextAsyncMiddleware
in a chain, or they can short circuit and return a customResponse
if desired.CORSMiddleware
Middleware that adds support for CORS settings in request responses. For configuration of this middleware please use the
CORSMiddleware.Configuration
object.ErrorMiddleware
Captures all errors and transforms them into an internal server error HTTP response.
FileMiddleware
Serves static files from a public directory.
RouteLoggingMiddleware
Emits a log message containing the request method and path to a
Request
's logger. The log level of the message is configurable.SessionsMiddleware
Uses HTTP cookies to save and restore sessions for connecting clients.
Default Implementations
makeResponder(chainingTo:)
Wraps a Responder
in a single Middleware
creating a new Responder
.
Requirements
respond(to:chainingTo:)
Called with each Request
that passes through this middleware.
Parameters
Name | Type | Description |
---|---|---|
request | Request |
The incoming |
next | Responder |
Next |
Returns
An asynchronous Response
.