pub trait CsrfRequestExt {
// Required method
fn rotate_csrf_token_in_response(
&self,
session_id: &str,
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 session_id = "user-session-id";
let mut resp = HttpResponse::Ok();
req.rotate_csrf_token_in_response(session_id, &mut resp)?;
Ok(resp.finish())
}Required Methods§
Sourcefn rotate_csrf_token_in_response(
&self,
session_id: &str,
resp: &mut HttpResponseBuilder,
) -> Result<(), Error>
fn rotate_csrf_token_in_response( &self, session_id: &str, resp: &mut HttpResponseBuilder, ) -> Result<(), Error>
Rotates the CSRF token and writes it to the outgoing response according to the configured pattern.