Skip to content

Commit

Permalink
Add handling of 307 and 308 redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanhs committed Nov 17, 2016
1 parent 6967f92 commit 5a5d29d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,30 @@ impl<'a> RequestBuilder<'a> {
match res.status {
StatusCode::MovedPermanently |
StatusCode::Found |
StatusCode::SeeOther => {
StatusCode::SeeOther |
StatusCode::TemporaryRedirect |
StatusCode::PermanentRedirect => {

//TODO: turn this into self.redirect_policy.check()
if redirect_count > 10 {
return Err(::Error::TooManyRedirects);
}
redirect_count += 1;

method = match method {
Method::Post | Method::Put => Method::Get,
m => m
};
match res.status {
StatusCode::MovedPermanently |
StatusCode::Found |
StatusCode::SeeOther => {
body = None;
method = match method {
Method::Post | Method::Put | Method::Delete => Method::Get,
m => m,
}
},
StatusCode::TemporaryRedirect |
StatusCode::PermanentRedirect => (),
_ => panic!(),
}

headers.set(Referer(url.to_string()));

Expand All @@ -239,7 +251,7 @@ impl<'a> RequestBuilder<'a> {
}
};

debug!("redirecting to '{}'", url);
debug!("redirecting to {:?} '{}'", method, url);

//TODO: removeSensitiveHeaders(&mut headers, &url);

Expand Down

0 comments on commit 5a5d29d

Please sign in to comment.