feature: expose redirect policy through extension#583
Open
unusual-thoughts wants to merge 4 commits intotower-rs:mainfrom
Open
feature: expose redirect policy through extension#583unusual-thoughts wants to merge 4 commits intotower-rs:mainfrom
unusual-thoughts wants to merge 4 commits intotower-rs:mainfrom
Conversation
seanmonstar
reviewed
Jun 11, 2025
c29a069 to
44b3401
Compare
Author
|
Rewrote to avoid breaking changes. Did my best to avoid code duplication, but some is unavoidable. |
536bde7 to
f348c2b
Compare
| #[derive(Clone, Copy, Debug)] | ||
| pub struct Limited { | ||
| remaining: usize, | ||
| pub(crate) remaining: usize, |
Author
There was a problem hiding this comment.
might be useful to make this fully public
f348c2b to
e2ecc29
Compare
a67dbfb to
f85fe10
Compare
ac346c1 to
4a5cec9
Compare
1351218 to
b9232a5
Compare
Collaborator
|
Here's another possible option, which I welcome feedback on from others: what if all that was added was a new method reqwest could then implement that method to insert an extension. |
Author
I suppose that could work too. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a
FollowedPolicyextension for theFollowRedirectmiddleware that exposes the policy struct to the response.Motivation
Currently there is no way to inspect the URLs (and status codes) that a redirected response took, as there is no way to "get back" the redirect policy struct from
follow_redirect::ResponseFuture.Custom redirect policies might have useful state that the user wants to access once the request completes. A typical use case would be to log the urls and status codes that have been traversed, which is already necessary for example to avoid loops.
This implements part of the modifications suggested in #404 as I understand it. It is also required to implement seanmonstar/reqwest#2606
Solution
Implement a
http::Extensions::Extensionthat stores a copy of thefollow_redirect::policy::Policystruct that was run on the last request of the redirect chain.Downsides
Currently this does another
clone()of the policy struct for each new request