Module tower_http::propagate_header [−][src]
This is supported on crate feature
propagate-header
only.Expand description
Propagate a header from the request to the response.
Example
use http::{Request, Response, header::HeaderName}; use std::convert::Infallible; use tower::{Service, ServiceExt, ServiceBuilder, service_fn}; use tower_http::propagate_header::PropagateHeaderLayer; use hyper::Body; async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> { // ... } let mut svc = ServiceBuilder::new() // This will copy `x-request-id` headers from requests onto responses. .layer(PropagateHeaderLayer::new(HeaderName::from_static("x-request-id"))) .service_fn(handle); // Call the service. let request = Request::builder() .header("x-request-id", "1337") .body(Body::empty())?; let response = svc.ready().await?.call(request).await?; assert_eq!(response.headers()["x-request-id"], "1337");
Structs
PropagateHeader | Middleware that propagates headers from requests to responses. |
PropagateHeaderLayer | Layer that applies |
ResponseFuture | Response future for |