This commit is contained in:
Jacob Hoffman-Andrews
2020-12-06 14:55:55 -08:00
parent ac93fa7e18
commit b9e3d3e76c
2 changed files with 6 additions and 2 deletions

View File

@@ -417,6 +417,8 @@ impl AgentBuilder {
/// let result = ureq::builder() /// let result = ureq::builder()
/// .redirects(1) /// .redirects(1)
/// .build() /// .build()
/// # ;
/// # let result = ureq::agent()
/// .get("http://httpbin.org/status/301") /// .get("http://httpbin.org/status/301")
/// .call()?; /// .call()?;
/// assert_ne!(result.status(), 301); /// assert_ne!(result.status(), 301);

View File

@@ -17,6 +17,8 @@ pub(crate) fn test_agent() -> Agent {
let headers = read_request(&stream); let headers = read_request(&stream);
if headers.0.is_empty() { if headers.0.is_empty() {
// no headers probably means it's the initial request to check test server is up. // no headers probably means it's the initial request to check test server is up.
} else if headers.path() == "/status/200" {
stream.write_all(b"HTTP/1.1 200 OK\r\n\r\n")?;
} else if headers.path() == "/status/500" { } else if headers.path() == "/status/500" {
stream.write_all(b"HTTP/1.1 500 Server Internal Error\r\n\r\n")?; stream.write_all(b"HTTP/1.1 500 Server Internal Error\r\n\r\n")?;
} else if headers.path() == "/bytes/100" { } else if headers.path() == "/bytes/100" {
@@ -30,11 +32,11 @@ pub(crate) fn test_agent() -> Agent {
stream.write_all(br#"{"hello": "world"}"#)?; stream.write_all(br#"{"hello": "world"}"#)?;
} else if headers.path() == "/status/301" { } else if headers.path() == "/status/301" {
stream.write_all(b"HTTP/1.1 301 Found\r\n")?; stream.write_all(b"HTTP/1.1 301 Found\r\n")?;
stream.write_all(b"Location: /redirect/3\r\n")?; stream.write_all(b"Location: /status/200\r\n")?;
stream.write_all(b"\r\n")?; stream.write_all(b"\r\n")?;
} else if headers.path() == "/status/307" { } else if headers.path() == "/status/307" {
stream.write_all(b"HTTP/1.1 307 Found\r\n")?; stream.write_all(b"HTTP/1.1 307 Found\r\n")?;
stream.write_all(b"Location: /redirect/3\r\n")?; stream.write_all(b"Location: /status/200\r\n")?;
stream.write_all(b"\r\n")?; stream.write_all(b"\r\n")?;
} else { } else {
stream.write_all(b"HTTP/1.1 200 OK\r\n")?; stream.write_all(b"HTTP/1.1 200 OK\r\n")?;