pub struct FollowRedirect<P = AlwaysRedirect> { /* private fields */ }client only.Expand description
Layer for following HTTP redirect responses.
This layer should be added as an outer client layer so that each redirected target is applied before service discovery and load balancing run for the next hop.
Each redirect hop is sent as a new request to the redirected target. Origin-specific headers
generated by the client, including Host, are updated for the next hop instead of preserving a
client-level Host override across the whole redirect chain.
Only in-memory request bodies can be replayed. If a redirect would require resending a non-cloneable streaming body, the layer returns a client error.
When combined with HttpProxy, this layer must wrap the
proxy layer so every follow-up hop re-enters the proxy. Prefer
ClientBuilder::follow_redirects, which
preserves this order for normally appended outer layers.
Implementations§
Source§impl FollowRedirect<AlwaysRedirect>
impl FollowRedirect<AlwaysRedirect>
Sourcepub const fn new(max_redirects: usize) -> Self
pub const fn new(max_redirects: usize) -> Self
Create a FollowRedirect layer that follows up to max_redirects redirects.
0 disables redirect following and returns redirect responses as-is.
Source§impl<P> FollowRedirect<P>
impl<P> FollowRedirect<P>
Sourcepub fn when<Next>(self, predicate: Next) -> FollowRedirect<Next>where
Next: RedirectPredicate,
pub fn when<Next>(self, predicate: Next) -> FollowRedirect<Next>where
Next: RedirectPredicate,
Set a predicate that decides which requests should enter redirect following.
Requests that do not match the predicate are passed through without cloning their request head for possible redirect replay. The predicate is also checked before each follow-up hop; if a redirect points to a target the predicate rejects, the redirect response is returned as-is.
Sourcepub const fn max_redirects(&self) -> usize
pub const fn max_redirects(&self) -> usize
Return the maximum number of redirects this layer will follow.
Trait Implementations§
Source§impl<P: Clone> Clone for FollowRedirect<P>
impl<P: Clone> Clone for FollowRedirect<P>
Source§fn clone(&self) -> FollowRedirect<P>
fn clone(&self) -> FollowRedirect<P>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more