diff --git a/src/request.rs b/src/request.rs index 7e8f751..792632e 100644 --- a/src/request.rs +++ b/src/request.rs @@ -121,7 +121,7 @@ impl Request { let response = unit::connect(unit, true, 0, reader, false).map_err(|e| e.url(url.clone()))?; - if response.error() && self.error_on_non_2xx { + if self.error_on_non_2xx && response.status() >= 400 { Err(Error::Status(response.status(), response)) } else { Ok(response) diff --git a/src/response.rs b/src/response.rs index e17bf32..1906995 100644 --- a/src/response.rs +++ b/src/response.rs @@ -145,30 +145,6 @@ impl Response { .collect() } - /// Whether the response status is: 200 <= status <= 299 - pub fn ok(&self) -> bool { - self.status >= 200 && self.status <= 299 - } - - pub fn redirect(&self) -> bool { - self.status >= 300 && self.status <= 399 - } - - /// Whether the response status is: 400 <= status <= 499 - pub fn client_error(&self) -> bool { - self.status >= 400 && self.status <= 499 - } - - /// Whether the response status is: 500 <= status <= 599 - pub fn server_error(&self) -> bool { - self.status >= 500 && self.status <= 599 - } - - /// Whether the response status is: 400 <= status <= 599 - pub fn error(&self) -> bool { - self.client_error() || self.server_error() - } - /// The content type part of the "Content-Type" header without /// the charset. /// diff --git a/src/test/simple.rs b/src/test/simple.rs index 5a45e78..842bc37 100644 --- a/src/test/simple.rs +++ b/src/test/simple.rs @@ -175,7 +175,6 @@ pub fn no_status_text() { test::make_response(200, "", vec![], vec![]) }); let resp = get("test://host/no_status_text").call().unwrap(); - assert!(resp.ok()); assert_eq!(resp.status(), 200); } diff --git a/src/unit.rs b/src/unit.rs index 934b6db..e434392 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -231,7 +231,7 @@ pub(crate) fn connect( save_cookies(&unit, &resp); // handle redirects - if resp.redirect() && unit.agent.config.redirects > 0 { + if (300..399).contains(&resp.status()) && unit.agent.config.redirects > 0 { if redirect_count == unit.agent.config.redirects { return Err(ErrorKind::TooManyRedirects.new()); }