tower_http/csrf/
response.rs1use http::{Response, StatusCode};
2
3use super::ProtectionError;
4
5pub trait ResponseForProtectionError<B>: Clone {
13 fn response_for_protection_error(&mut self, error: ProtectionError) -> Response<B>;
15}
16
17impl<F, B> ResponseForProtectionError<B> for F
18where
19 F: FnMut(ProtectionError) -> Response<B> + Clone,
20{
21 fn response_for_protection_error(&mut self, error: ProtectionError) -> Response<B> {
22 self(error)
23 }
24}
25
26#[derive(Clone, Copy, Debug, Default)]
35#[non_exhaustive]
36pub struct DefaultResponseForProtectionError;
37
38impl<B: Default> ResponseForProtectionError<B> for DefaultResponseForProtectionError {
39 fn response_for_protection_error(&mut self, _error: ProtectionError) -> Response<B> {
40 let mut response = Response::new(B::default());
41 *response.status_mut() = StatusCode::FORBIDDEN;
42
43 response
44 }
45}