Vapor Documentation Beta

Class Sessions​Middleware

public final class SessionsMiddleware: Middleware

Uses HTTP cookies to save and restore sessions for connecting clients.

If a cookie matching the configured cookie name is found on an incoming request, the value will be used as an identifier to find the associated Session.

If a session is used during a request (Request.session()), a cookie will be set on the outgoing response with the session's unique identifier. This cookie must be returned on the next request to restore the session.

var middlewareConfig = MiddlewareConfig()
middlewareConfig.use(SessionsMiddleware.self)
services.register(middlewareConfig)

See SessionsConfig and Sessions for more information.

%3 SessionsMiddleware SessionsMiddleware Middleware Middleware SessionsMiddleware->Middleware

Conforms To

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.

Initializers

init(session:​configuration:​)

public init(session: SessionDriver, configuration: SessionsConfiguration = .default())

Creates a new SessionsMiddleware.

Parameters

sessions

Sessions implementation to use for fetching and storing sessions.

configuration Sessions​Configuration

SessionsConfiguration to use for naming and creating cookie values.

Properties

session

let session: SessionDriver

Session store.

Methods

respond(to:​chaining​To:​)

public func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response>

See Middleware.respond