-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Customizable Redirect Policy #24
Comments
Well, currently reqwest effectively has a redirect policy of My crate interfaces with a web API that sometimes sends a redirect to a login page instead of a 401/403 response, so by preventing that redirect I'm able to report an equivalent error to the caller of my function instead of trying to deserialize an HTML page as JSON. I also plan in the future to prevent redirects from taking me to hostnames outside of a whitelist to prevent abuse. |
I've felt that the
Looking at other implementations for inspiration, there is this in golang's CheckRedirect func(req *Request, via []*Request) error This allows a user to a) count the number of previous requests, b) check for duplicate URLs, among other things. If I understand Go enough, I believe that also means the So, the design I've been thinking of looks something like this: trait Redirect {
fn redirect(&self, next: &Url, previous: &[Url]) -> bool;
}
impl Client {
pub fn set_redirect_policy<T: Redirect>(&mut self, policy: T) {
self.redirect_policy = Box::new(policy);
}
} The There could be a couple built-ins, such as:
It would also allow custom policies like this: let max_redirects = config.load('max_redirects').unwrap_or(5);
client.set_redirect_policy(move |_next, previous| {
previous.len() >= max_redirects
}) |
That sounds good. Maybe you can also add operators to combine redirect policies but that can be done in user code as well. |
I have an implementation in #29. I ended up not having a |
Fix broken examples on Readme.md, add examples
No description provided.
The text was updated successfully, but these errors were encountered: