CsrfRequestExt

Trait CsrfRequestExt 

Source
pub trait CsrfRequestExt {
    // Required method
    fn rotate_csrf_token_in_response(
        &self,
        resp: &mut HttpResponseBuilder,
    ) -> Result<(), Error>;
}
Expand description

Extension trait for Actix HttpRequest to rotate the CSRF token in a response.

This is a convenience wrapper around rotate_csrf_token_in_response, allowing you to rotate tokens without passing configuration explicitly. Typical use-cases include rotating the token immediately after login or privilege escalation.

§Examples

Rotate after a successful login:

use actix_csrf_middleware::CsrfRequestExt;
use actix_web::{HttpRequest, HttpResponse};

async fn after_login(req: HttpRequest) -> actix_web::Result<HttpResponse> {
    let mut resp = HttpResponse::Ok();
    req.rotate_csrf_token_in_response(&mut resp)?;
    Ok(resp.finish())
}

Required Methods§

Source

fn rotate_csrf_token_in_response( &self, resp: &mut HttpResponseBuilder, ) -> Result<(), Error>

Rotates the CSRF token and writes it to the outgoing response according to the configured pattern.

Implementations on Foreign Types§

Source§

impl CsrfRequestExt for HttpRequest

Implementors§