Skip to content

Commit

Permalink
Note that 307 redirects aren't followed in the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 authored and algesten committed Dec 5, 2020
1 parent 6bab430 commit 4a3d3c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,24 @@ impl AgentBuilder {
///
/// If the redirect count hits this limit (and it's > 0), TooManyRedirects is returned.
///
/// WARNING: for 307 and 308 redirects, this value is ignored for methods that have a body.
/// You must handle 307 redirects yourself when sending a PUT, POST, PATCH, or DELETE request.
///
/// ```
/// # fn main() -> Result<(), ureq::Error> {
/// # ureq::is_test(true);
/// let result = ureq::builder()
/// .redirects(1)
/// .build()
/// .get("http://httpbin.org/redirect/3")
/// .call();
/// .get("http://httpbin.org/status/301")
/// .error_on_non_2xx(false)
/// .call()?;
/// assert_ne!(result.status(), 301);
///
/// let result = ureq::post("http://httpbin.org/status/307")
/// .error_on_non_2xx(false)
/// .send_bytes(b"some data")?;
/// assert_eq!(result.status(), 307);
/// # Ok(())
/// # }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/testserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub(crate) fn test_agent() -> Agent {
stream.write_all(b"HTTP/1.1 200 OK\r\n")?;
stream.write_all(b"\r\n")?;
stream.write_all(br#"{"hello": "world"}"#)?;
} else if headers.path() == "/redirect/3" {
stream.write_all(b"HTTP/1.1 302 Found\r\n")?;
} else if headers.path() == "/status/307" {
stream.write_all(b"HTTP/1.1 307 Found\r\n")?;
stream.write_all(b"Location: /redirect/3\r\n")?;
stream.write_all(b"\r\n")?;
} else {
Expand Down

0 comments on commit 4a3d3c4

Please sign in to comment.