//! Chain service for decompressing request payload. use std::marker::PhantomData; use actix_http::encoding::Decoder; use actix_service::{NewService, Service}; use bytes::Bytes; use futures::future::{ok, FutureResult}; use futures::{Async, Poll, Stream}; use crate::dev::Payload; use crate::error::{Error, PayloadError}; use crate::service::ServiceRequest; use crate::HttpMessage; /// `Middleware` for decompressing request's payload. /// `Decompress` middleware must be added with `App::chain()` method. /// /// ```rust /// use actix_web::{web, middleware::encoding, App, HttpResponse}; /// /// fn main() { /// let app = App::new() /// .chain(encoding::Decompress::new()) /// .service( /// web::resource("/test") /// .route(web::get().to(|| HttpResponse::Ok())) /// .route(web::head().to(|| HttpResponse::MethodNotAllowed())) /// ); /// } /// ``` pub struct Decompress

(PhantomData

); impl

Decompress

where P: Stream, { pub fn new() -> Self { Decompress(PhantomData) } } impl

NewService for Decompress

where P: Stream, { type Request = ServiceRequest

; type Response = ServiceRequest>>; type Error = Error; type InitError = (); type Service = Decompress

; type Future = FutureResult; fn new_service(&self, _: &()) -> Self::Future { ok(Decompress(PhantomData)) } } impl

Service for Decompress

where P: Stream, { type Request = ServiceRequest

; type Response = ServiceRequest>>; type Error = Error; type Future = FutureResult; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) } fn call(&mut self, req: ServiceRequest

) -> Self::Future { let (req, payload) = req.into_parts(); let payload = Decoder::from_headers(req.headers(), payload); ok(ServiceRequest::from_parts(req, Payload::Stream(payload))) } }