Trait actix_web::dev::Transform [−][src]
pub trait Transform<S, Req> { type Response; type Error; type Transform: Service<Req>; type InitError; type Future: Future; pub fn new_transform(&self, service: S) -> Self::Future; }
Defines the interface of a service factory that wraps inner service during construction.
Transformers wrap an inner service and runs during inbound and/or outbound processing in the service lifecycle. It may modify request and/or response.
For example, a timeout service wrapper:
pub struct Timeout<S> { service: S, timeout: Duration, } impl<S: Service<Req>, Req> Service<Req> for Timeout<S> { type Response = S::Response; type Error = TimeoutError<S::Error>; type Future = TimeoutServiceResponse<S>; actix_service::forward_ready!(service); fn call(&self, req: S::Request) -> Self::Future { TimeoutServiceResponse { fut: self.service.call(req), sleep: Sleep::new(clock::now() + self.timeout), } } }
This wrapper service is decoupled from the underlying service implementation and could be applied to any service.
The Transform
trait defines the interface of a service wrapper. Transform
is often
implemented for middleware, defining how to construct a middleware Service. A Service that is
constructed by the factory takes the Service that follows it during execution as a parameter,
assuming ownership of the next Service.
A transform for the Timeout
middleware could look like this:
pub struct TimeoutTransform { timeout: Duration, } impl<S: Service<Req>, Req> Transform<S, Req> for TimeoutTransform { type Response = S::Response; type Error = TimeoutError<S::Error>; type InitError = S::Error; type Transform = Timeout<S>; type Future = Ready<Result<Self::Transform, Self::InitError>>; fn new_transform(&self, service: S) -> Self::Future { ready(Ok(Timeout { service, timeout: self.timeout, })) } }
Associated Types
type Response
[src]
Responses produced by the service.
type Error
[src]
Errors produced by the service.
type Transform: Service<Req>
[src]
The TransformService
value created by this factory
type InitError
[src]
Errors produced while building a transform service.
type Future: Future
[src]
The future response value.
Required methods
pub fn new_transform(&self, service: S) -> Self::Future
[src]
Creates and returns a new Transform component, asynchronously
Implementations on Foreign Types
impl<T, S, Req> Transform<S, Req> for Arc<T> where
T: Transform<S, Req>,
[src]
T: Transform<S, Req>,
type Response = <T as Transform<S, Req>>::Response
type Error = <T as Transform<S, Req>>::Error
type Transform = <T as Transform<S, Req>>::Transform
type InitError = <T as Transform<S, Req>>::InitError
type Future = <T as Transform<S, Req>>::Future
pub fn new_transform(&self, service: S) -> <T as Transform<S, Req>>::Future
[src]
impl<T, S, Req> Transform<S, Req> for Rc<T> where
T: Transform<S, Req>,
[src]
T: Transform<S, Req>,
type Response = <T as Transform<S, Req>>::Response
type Error = <T as Transform<S, Req>>::Error
type Transform = <T as Transform<S, Req>>::Transform
type InitError = <T as Transform<S, Req>>::InitError
type Future = <T as Transform<S, Req>>::Future
pub fn new_transform(&self, service: S) -> <T as Transform<S, Req>>::Future
[src]
Implementors
impl<S, B> Transform<S, ServiceRequest> for Compress where
B: MessageBody,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
[src]
B: MessageBody,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
type Response = ServiceResponse<Encoder<B>>
type Error = Error
type Transform = CompressMiddleware<S>
type InitError = ()
type Future = Ready<Result<Self::Transform, Self::InitError>>
fn new_transform(&self, service: S) -> Self::Future
[src]
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
[src]
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
type Response = ServiceResponse<B>
type Error = Error
type Transform = DefaultHeadersMiddleware<S>
type InitError = ()
type Future = Ready<Result<Self::Transform, Self::InitError>>
fn new_transform(&self, service: S) -> Self::Future
[src]
impl<S, B> Transform<S, ServiceRequest> for ErrorHandlers<B> where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: 'static,
[src]
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: 'static,
type Response = ServiceResponse<B>
type Error = Error
type Transform = ErrorHandlersMiddleware<S, B>
type InitError = ()
type Future = LocalBoxFuture<'static, Result<Self::Transform, Self::InitError>>
fn new_transform(&self, service: S) -> Self::Future
[src]
impl<S, B> Transform<S, ServiceRequest> for Logger where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
[src]
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
type Response = ServiceResponse<StreamLog<B>>
type Error = Error
type InitError = ()
type Transform = LoggerMiddleware<S>
type Future = Ready<Result<Self::Transform, Self::InitError>>
fn new_transform(&self, service: S) -> Self::Future
[src]
impl<S, B> Transform<S, ServiceRequest> for NormalizePath where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
[src]
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
type Response = ServiceResponse<B>
type Error = Error
type Transform = NormalizePathNormalization<S>
type InitError = ()
type Future = Ready<Result<Self::Transform, Self::InitError>>
fn new_transform(&self, service: S) -> Self::Future
[src]
impl<S, T, Req> Transform<S, Req> for Compat<T> where
S: Service<Req>,
T: Transform<S, Req>,
T::Future: 'static,
T::Response: MapServiceResponseBody,
Error: From<T::Error>,
[src]
S: Service<Req>,
T: Transform<S, Req>,
T::Future: 'static,
T::Response: MapServiceResponseBody,
Error: From<T::Error>,
type Response = ServiceResponse
type Error = Error
type Transform = CompatMiddleware<T::Transform>
type InitError = T::InitError
type Future = LocalBoxFuture<'static, Result<Self::Transform, Self::InitError>>
fn new_transform(&self, service: S) -> Self::Future
[src]
impl<S, T, Req> Transform<S, Req> for Condition<T> where
S: Service<Req> + 'static,
T: Transform<S, Req, Response = S::Response, Error = S::Error>,
T::Future: 'static,
T::InitError: 'static,
T::Transform: 'static,
[src]
S: Service<Req> + 'static,
T: Transform<S, Req, Response = S::Response, Error = S::Error>,
T::Future: 'static,
T::InitError: 'static,
T::Transform: 'static,