rama_http/layer/csrf/
response.rs1use super::ProtectionError;
2use crate::{Response, StatusCode};
3
4pub trait ResponseForProtectionError<B>: Clone + Send + Sync + 'static {
12 fn response_for_protection_error(&self, error: ProtectionError) -> Response<B>;
14}
15
16impl<F, B> ResponseForProtectionError<B> for F
17where
18 F: Fn(ProtectionError) -> Response<B> + Clone + Send + Sync + 'static,
19{
20 fn response_for_protection_error(&self, error: ProtectionError) -> Response<B> {
21 self(error)
22 }
23}
24
25#[derive(Clone, Copy, Debug, Default)]
33#[non_exhaustive]
34pub struct DefaultResponseForProtectionError;
35
36impl<B: Default> ResponseForProtectionError<B> for DefaultResponseForProtectionError {
37 fn response_for_protection_error(&self, _error: ProtectionError) -> Response<B> {
38 let mut response = Response::new(B::default());
39 *response.status_mut() = StatusCode::FORBIDDEN;
40 response
41 }
42}