-
Notifications
You must be signed in to change notification settings - Fork 201
feature: expose redirect policy through extension #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feature: expose redirect policy through extension #583
Conversation
c29a069
to
44b3401
Compare
Rewrote to avoid breaking changes. Did my best to avoid code duplication, but some is unavoidable. |
536bde7
to
f348c2b
Compare
@@ -3,7 +3,7 @@ use super::{Action, Attempt, Policy}; | |||
/// A redirection [`Policy`] that limits the number of successive redirections. | |||
#[derive(Clone, Copy, Debug)] | |||
pub struct Limited { | |||
remaining: usize, | |||
pub(crate) remaining: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be useful to make this fully public
f348c2b
to
e2ecc29
Compare
a67dbfb
to
f85fe10
Compare
ac346c1
to
4a5cec9
Compare
1351218
to
b9232a5
Compare
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. |
I suppose that could work too. |
This adds a
FollowedPolicy
extension for theFollowRedirect
middleware 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::Extension
that stores a copy of thefollow_redirect::policy::Policy
struct 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