1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! A no-op middleware. See [Noop] for docs.

use actix_utils::future::{ready, Ready};

use crate::dev::{forward_ready, Service, Transform};

/// A no-op middleware that passes through request and response untouched.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct Identity;

impl<S: Service<Req>, Req> Transform<S, Req> for Identity {
    type Response = S::Response;
    type Error = S::Error;
    type Transform = IdentityMiddleware<S>;
    type InitError = ();
    type Future = Ready<Result<Self::Transform, Self::InitError>>;

    #[inline]
    fn new_transform(&self, service: S) -> Self::Future {
        ready(Ok(IdentityMiddleware { service }))
    }
}

#[doc(hidden)]
pub struct IdentityMiddleware<S> {
    service: S,
}

impl<S: Service<Req>, Req> Service<Req> for IdentityMiddleware<S> {
    type Response = S::Response;
    type Error = S::Error;
    type Future = S::Future;

    forward_ready!(service);

    #[inline]
    fn call(&self, req: Req) -> Self::Future {
        self.service.call(req)
    }
}