Module tower_http::decompression [−][src]
This is supported on crate feature
decompression
only.Expand description
Middleware that decompresses response bodies.
Example
use bytes::BytesMut; use http::{Request, Response}; use http_body::Body as _; // for Body::data use hyper::Body; use std::convert::Infallible; use tower::{Service, ServiceExt, ServiceBuilder, service_fn}; use tower_http::{compression::Compression, decompression::DecompressionLayer}; // Some opaque service that applies compression. let service = Compression::new(service_fn(handle)); // Our HTTP client. let mut client = ServiceBuilder::new() // Automatically decompress response bodies. .layer(DecompressionLayer::new()) .service(service); // Call the service. // // `DecompressionLayer` takes care of setting `Accept-Encoding`. let request = Request::new(Body::empty()); let response = client .ready() .await? .call(request) .await?; // Read the body let mut body = response.into_body(); let mut bytes = BytesMut::new(); while let Some(chunk) = body.data().await { let chunk = chunk?; bytes.extend_from_slice(&chunk[..]); } let body = String::from_utf8(bytes.to_vec())?; assert_eq!(body, "Hello, World!");
Structs
Decompression | Decompresses response bodies of the underlying service. |
DecompressionBody | Response body of |
DecompressionLayer | Decompresses response bodies of the underlying service. |
ResponseFuture | Response future of |