pub struct CsrfMiddleware { /* private fields */ }
Expand description
Cross-Site Request Forgery (CSRF) protection middleware.
Implementations§
Source§impl CsrfMiddleware
impl CsrfMiddleware
Sourcepub fn new(secret: &[u8]) -> Self
pub fn new(secret: &[u8]) -> Self
Create a new instance.
§Defaults
The defaults for CsrfMiddleware are:
- cookie path:
/
- cookie name:
tide.csrf
- cookie domain: None
- ttl: 24 hours
- header name:
X-CSRF-Token
- query param:
csrf-token
- form field:
csrf-token
- protected methods:
[POST, PUT, PATCH, DELETE]
Sourcepub fn with_ttl(self, ttl: Duration) -> Self
pub fn with_ttl(self, ttl: Duration) -> Self
Sets the protection ttl. This will be used for both the cookie expiry and the time window over which CSRF tokens are considered valid.
The default for this value is one day.
Sourcepub fn with_header_name(self, header_name: impl AsRef<str>) -> Self
pub fn with_header_name(self, header_name: impl AsRef<str>) -> Self
Sets the name of the HTTP header where the middleware will look for the CSRF token.
Defaults to “X-CSRF-Token”.
Sourcepub fn with_query_param(self, query_param: impl AsRef<str>) -> Self
pub fn with_query_param(self, query_param: impl AsRef<str>) -> Self
Sets the name of the query parameter where the middleware will look for the CSRF token.
Defaults to “csrf-token”.
Sourcepub fn with_form_field(self, form_field: impl AsRef<str>) -> Self
pub fn with_form_field(self, form_field: impl AsRef<str>) -> Self
Sets the name of the form field where the middleware will look for the CSRF token.
Defaults to “csrf-token”.
Sourcepub fn with_protected_methods(self, methods: &[Method]) -> Self
pub fn with_protected_methods(self, methods: &[Method]) -> Self
Sets the list of methods that will be protected by this middleware
Defaults to [POST, PUT, PATCH, DELETE]
Trait Implementations§
Source§impl Debug for CsrfMiddleware
impl Debug for CsrfMiddleware
Source§impl<State> Middleware<State> for CsrfMiddleware
impl<State> Middleware<State> for CsrfMiddleware
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
req: Request<State>,
next: Next<'life1, State>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
req: Request<State>,
next: Next<'life1, State>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Asynchronously handle the request, and return a response.
Auto Trait Implementations§
impl Freeze for CsrfMiddleware
impl RefUnwindSafe for CsrfMiddleware
impl Send for CsrfMiddleware
impl Sync for CsrfMiddleware
impl Unpin for CsrfMiddleware
impl UnwindSafe for CsrfMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more