Skip to content

Commit 7def5a8

Browse files
committed
Note that 307 redirects aren't followed in the docs
1 parent 47958c3 commit 7def5a8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/agent.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,24 @@ impl AgentBuilder {
408408
///
409409
/// If the redirect count hits this limit (and it's > 0), TooManyRedirects is returned.
410410
///
411+
/// WARNING: for 307 and 308 redirects, this value is ignored for methods that have a body.
412+
/// You must handle 307 redirects yourself when sending a PUT, POST, PATCH, or DELETE request.
413+
///
411414
/// ```
412415
/// # fn main() -> Result<(), ureq::Error> {
413416
/// # ureq::is_test(true);
414417
/// let result = ureq::builder()
415418
/// .redirects(1)
416419
/// .build()
417-
/// .get("http://httpbin.org/redirect/3")
418-
/// .call();
420+
/// .get("http://httpbin.org/status/301")
421+
/// .error_on_non_2xx(false)
422+
/// .call()?;
423+
/// assert_ne!(result.status(), 301);
424+
///
425+
/// let result = ureq::post("http://httpbin.org/status/307")
426+
/// .error_on_non_2xx(false)
427+
/// .send_bytes(b"some data")?;
428+
/// assert_eq!(result.status(), 307);
419429
/// # Ok(())
420430
/// # }
421431
/// ```

src/testserver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub(crate) fn test_agent() -> Agent {
2828
stream.write_all(b"HTTP/1.1 200 OK\r\n")?;
2929
stream.write_all(b"\r\n")?;
3030
stream.write_all(br#"{"hello": "world"}"#)?;
31-
} else if headers.path() == "/redirect/3" {
32-
stream.write_all(b"HTTP/1.1 302 Found\r\n")?;
31+
} else if headers.path() == "/status/307" {
32+
stream.write_all(b"HTTP/1.1 307 Found\r\n")?;
3333
stream.write_all(b"Location: /redirect/3\r\n")?;
3434
stream.write_all(b"\r\n")?;
3535
} else {

0 commit comments

Comments
 (0)