pub struct CsrfLayer {
    pub regenerate_token: RegenerateToken,
    pub request_header: &'static str,
    pub response_header: &'static str,
    pub session_key: &'static str,
}
Expand description

Use CsrfLayer::new() to provide the middleware and configuration to axum’s service stack.

Use the provided methods to configure details, such as when tokens are regenerated, what request and response headers should be named, and under which key the token should be stored in the session.

Fields§

§regenerate_token: RegenerateToken

Configures when tokens are regenerated: Per session, per use or per request. See RegenerateToken for details.

§request_header: &'static str

Configures the request header name accepted by the middleware. Defaults to "X-CSRF-TOKEN". This header is set on your JavaScript or WASM requests originating from the browser.

§response_header: &'static str

Configures the response header name sent by the middleware. Defaults to "X-CSRF-TOKEN". This header is received by your JavaScript or WASM code and its name must be used to extract the token from the HTTP response.

§session_key: &'static str

Configures the key under which the middleware stores the server-side token in the session. Defaults to "_csrf_token".

Implementations§

Create a new CSRF synchronizer token layer to inject into your middleware stack using axum::Router::layer().

Configure when tokens are regenerated: Per session, per use or per request. See RegenerateToken for details.

Configure a custom request header name accepted by the middleware. Defaults to "X-CSRF-TOKEN".

This header is set on your JavaScript or WASM requests originating from the browser.

Configure a custom response header name sent by the middleware. Defaults to "X-CSRF-TOKEN".

This header is received by your JavaScript or WASM code and its name must be used to extract the token from the HTTP response.

Configure a custom key under which the middleware stores the server-side token in the session. Defaults to "_csrf_token".

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The wrapped service
Wrap the given service with the middleware, returning a new service that has been decorated with the middleware. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Converts to this type from a reference to the input type.
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more