diff --git a/tower-http/src/follow_redirect/mod.rs b/tower-http/src/follow_redirect/mod.rs index a90e0825..8c87285c 100644 --- a/tower-http/src/follow_redirect/mod.rs +++ b/tower-http/src/follow_redirect/mod.rs @@ -6,8 +6,7 @@ //! redirections. //! //! The middleware tries to clone the original [`Request`] when making a redirected request. -//! However, since [`Extensions`][http::Extensions] are `!Clone`, any extensions set by outer -//! middleware will be discarded. Also, the request body cannot always be cloned. When the +//! However, the request body cannot always be cloned. When the //! original body is known to be empty by [`Body::size_hint`], the middleware uses `Default` //! implementation of the body type to create a new request body. If you know that the body can be //! cloned in some way, you can tell the middleware to clone it by configuring a [`policy`]. @@ -98,8 +97,8 @@ use self::policy::{Action, Attempt, Policy, Standard}; use futures_util::future::Either; use http::{ header::CONTENT_ENCODING, header::CONTENT_LENGTH, header::CONTENT_TYPE, header::LOCATION, - header::TRANSFER_ENCODING, HeaderMap, HeaderValue, Method, Request, Response, StatusCode, Uri, - Version, + header::TRANSFER_ENCODING, Extensions, HeaderMap, HeaderValue, Method, Request, Response, + StatusCode, Uri, Version, }; use http_body::Body; use iri_string::types::{UriAbsoluteString, UriReferenceStr}; @@ -219,6 +218,7 @@ where uri: req.uri().clone(), version: req.version(), headers: req.headers().clone(), + extensions: req.extensions().clone(), body, future: Either::Left(service.call(req)), service, @@ -242,6 +242,7 @@ pin_project! { uri: Uri, version: Version, headers: HeaderMap, + extensions: Extensions, body: BodyRepr, } } @@ -322,6 +323,7 @@ where *req.method_mut() = this.method.clone(); *req.version_mut() = *this.version; *req.headers_mut() = this.headers.clone(); + *req.extensions_mut() = this.extensions.clone(); this.policy.on_request(&mut req); this.future .set(Either::Right(Oneshot::new(this.service.clone(), req)));