pub struct CsrfToken(pub String);
Expand description
Extractor for the current CSRF token.
- On safe requests (GET/HEAD), ensures a token exists and makes it available to handlers.
- On mutating requests (POST/PUT/PATCH/DELETE), extracting
CsrfToken
verifies the token before your handler is called; if verification fails, the request is rejected and your handler is not executed.
§Examples
Read the token in a form-rendering handler and embed it into HTML or a JSON response.
use actix_csrf_middleware::CsrfToken;
use actix_web::{HttpResponse, Responder};
async fn form(csrf: CsrfToken) -> impl Responder {
HttpResponse::Ok().body(format!("token:{}", csrf.0))
}
Note: Using this extractor requires the middleware to be installed via
CsrfMiddleware::new
. If not configured, extraction will fail with an internal error.
Tuple Fields§
§0: String
Trait Implementations§
Source§impl FromRequest for CsrfToken
impl FromRequest for CsrfToken
Auto Trait Implementations§
impl Freeze for CsrfToken
impl RefUnwindSafe for CsrfToken
impl Send for CsrfToken
impl Sync for CsrfToken
impl Unpin for CsrfToken
impl UnwindSafe for CsrfToken
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