actix_modsecurity/
factory.rs1use std::future::{Ready, ready};
2use std::rc::Rc;
3
4use actix_web::{
5 Error,
6 body::BoxBody,
7 dev::{Service, ServiceRequest, ServiceResponse, Transform},
8};
9
10use crate::ModSecurityService;
11use crate::modsecurity::ModSecurity;
12use crate::service::ModSecurityInner;
13
14pub struct Middleware(Rc<ModSecurity>);
33
34impl Middleware {
35 #[inline]
37 pub fn new(modsecurity: ModSecurity) -> Self {
38 Self(Rc::new(modsecurity))
39 }
40}
41
42impl<S> Transform<S, ServiceRequest> for Middleware
43where
44 S: Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> + 'static,
45 S::Future: 'static,
46{
47 type Response = ServiceResponse<BoxBody>;
48 type Error = Error;
49 type InitError = ();
50 type Transform = ModSecurityService<S>;
51 type Future = Ready<Result<Self::Transform, Self::InitError>>;
52
53 fn new_transform(&self, service: S) -> Self::Future {
54 ready(Ok(ModSecurityService(Rc::new(ModSecurityInner {
55 service: Rc::new(service),
56 modsecurity: Rc::clone(&self.0),
57 }))))
58 }
59}