Note that 307 redirects aren't followed in the docs

This commit is contained in:
Joshua Nelson
2020-12-03 08:26:40 -05:00
committed by Martin Algesten
parent 6bab430d29
commit 4a3d3c49a1
2 changed files with 14 additions and 4 deletions

View File

@@ -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(())
/// # }
/// ```

View File

@@ -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 {