From 4a3d3c49a19748887879ddccc0465fd5984e215e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 3 Dec 2020 08:26:40 -0500 Subject: [PATCH] Note that 307 redirects aren't followed in the docs --- src/agent.rs | 14 ++++++++++++-- src/testserver.rs | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index 5bb9a736..60f6a132 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -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(()) /// # } /// ``` diff --git a/src/testserver.rs b/src/testserver.rs index a2eb4a99..28588305 100644 --- a/src/testserver.rs +++ b/src/testserver.rs @@ -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 {