style(client): use status.is_redirection()
This commit is contained in:
@@ -66,7 +66,6 @@ use header::{Headers, Header, HeaderFormat};
|
|||||||
use header::{ContentLength, Location};
|
use header::{ContentLength, Location};
|
||||||
use method::Method;
|
use method::Method;
|
||||||
use net::{NetworkConnector, NetworkStream, ContextVerifier};
|
use net::{NetworkConnector, NetworkStream, ContextVerifier};
|
||||||
use status::StatusClass::Redirection;
|
|
||||||
use {Url};
|
use {Url};
|
||||||
use Error;
|
use Error;
|
||||||
|
|
||||||
@@ -87,6 +86,8 @@ use http::h1::Http11Protocol;
|
|||||||
pub struct Client {
|
pub struct Client {
|
||||||
protocol: Box<Protocol + Send + Sync>,
|
protocol: Box<Protocol + Send + Sync>,
|
||||||
redirect_policy: RedirectPolicy,
|
redirect_policy: RedirectPolicy,
|
||||||
|
#[cfg(feature = "timeouts")]
|
||||||
|
read_timeout: Option<Duration>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
@@ -125,6 +126,12 @@ impl Client {
|
|||||||
self.redirect_policy = policy;
|
self.redirect_policy = policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the read timeout value for all requests.
|
||||||
|
#[cfg(feature = "timeouts")]
|
||||||
|
pub fn set_read_timeout(&mut self, dur: Option<Duration>) {
|
||||||
|
self.read_timeout = dur;
|
||||||
|
}
|
||||||
|
|
||||||
/// Build a Get request.
|
/// Build a Get request.
|
||||||
pub fn get<U: IntoUrl>(&self, url: U) -> RequestBuilder<U> {
|
pub fn get<U: IntoUrl>(&self, url: U) -> RequestBuilder<U> {
|
||||||
self.request(Method::Get, url)
|
self.request(Method::Get, url)
|
||||||
@@ -245,7 +252,7 @@ impl<'a, U: IntoUrl> RequestBuilder<'a, U> {
|
|||||||
let mut streaming = try!(req.start());
|
let mut streaming = try!(req.start());
|
||||||
body.take().map(|mut rdr| copy(&mut rdr, &mut streaming));
|
body.take().map(|mut rdr| copy(&mut rdr, &mut streaming));
|
||||||
let res = try!(streaming.send());
|
let res = try!(streaming.send());
|
||||||
if res.status.class() != Redirection {
|
if !res.status.is_redirection() {
|
||||||
return Ok(res)
|
return Ok(res)
|
||||||
}
|
}
|
||||||
debug!("redirect code {:?} for {}", res.status, url);
|
debug!("redirect code {:?} for {}", res.status, url);
|
||||||
|
|||||||
Reference in New Issue
Block a user