Really trivial rustfmt changes.
This commit is contained in:
		| @@ -1,7 +1,9 @@ | |||||||
| //! `cargo run --example response_json` | //! `cargo run --example response_json` | ||||||
| extern crate reqwest; | extern crate reqwest; | ||||||
| #[macro_use] extern crate serde_derive; | #[macro_use] | ||||||
| #[macro_use] extern crate error_chain; | extern crate serde_derive; | ||||||
|  | #[macro_use] | ||||||
|  | extern crate error_chain; | ||||||
|  |  | ||||||
| error_chain! { | error_chain! { | ||||||
|     foreign_links { |     foreign_links { | ||||||
|   | |||||||
| @@ -1,7 +1,8 @@ | |||||||
| //! `cargo run --example simple` | //! `cargo run --example simple` | ||||||
| extern crate reqwest; | extern crate reqwest; | ||||||
| extern crate env_logger; | extern crate env_logger; | ||||||
| #[macro_use] extern crate error_chain; | #[macro_use] | ||||||
|  | extern crate error_chain; | ||||||
|  |  | ||||||
| error_chain! { | error_chain! { | ||||||
|     foreign_links { |     foreign_links { | ||||||
|   | |||||||
| @@ -5,11 +5,11 @@ use std::time::Duration; | |||||||
|  |  | ||||||
| use hyper::client::IntoUrl; | use hyper::client::IntoUrl; | ||||||
| use hyper::header::{Headers, ContentType, Location, Referer, UserAgent, Accept, Encoding, | use hyper::header::{Headers, ContentType, Location, Referer, UserAgent, Accept, Encoding, | ||||||
|     AcceptEncoding, Range, qitem}; |                     AcceptEncoding, Range, qitem}; | ||||||
| use hyper::method::Method; | use hyper::method::Method; | ||||||
| use hyper::status::StatusCode; | use hyper::status::StatusCode; | ||||||
| use hyper::version::HttpVersion; | use hyper::version::HttpVersion; | ||||||
| use hyper::{Url}; | use hyper::Url; | ||||||
|  |  | ||||||
| use hyper_native_tls::{NativeTlsClient, native_tls}; | use hyper_native_tls::{NativeTlsClient, native_tls}; | ||||||
|  |  | ||||||
| @@ -17,9 +17,9 @@ use serde::Serialize; | |||||||
| use serde_json; | use serde_json; | ||||||
| use serde_urlencoded; | use serde_urlencoded; | ||||||
|  |  | ||||||
| use ::body::{self, Body}; | use body::{self, Body}; | ||||||
| use ::redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers}; | use redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers}; | ||||||
| use ::response::Response; | use response::Response; | ||||||
|  |  | ||||||
| static DEFAULT_USER_AGENT: &'static str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); | static DEFAULT_USER_AGENT: &'static str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); | ||||||
|  |  | ||||||
| @@ -328,7 +328,8 @@ impl RequestBuilder { | |||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
|     pub fn header<H>(mut self, header: H) -> RequestBuilder |     pub fn header<H>(mut self, header: H) -> RequestBuilder | ||||||
|     where H: ::header::Header + ::header::HeaderFormat |     where | ||||||
|  |         H: ::header::Header + ::header::HeaderFormat, | ||||||
|     { |     { | ||||||
|         self.headers.set(header); |         self.headers.set(header); | ||||||
|         self |         self | ||||||
| @@ -343,7 +344,9 @@ impl RequestBuilder { | |||||||
|  |  | ||||||
|     /// Enable HTTP basic authentication. |     /// Enable HTTP basic authentication. | ||||||
|     pub fn basic_auth<U, P>(self, username: U, password: Option<P>) -> RequestBuilder |     pub fn basic_auth<U, P>(self, username: U, password: Option<P>) -> RequestBuilder | ||||||
|             where U: Into<String>, P: Into<String> |     where | ||||||
|  |         U: Into<String>, | ||||||
|  |         P: Into<String>, | ||||||
|     { |     { | ||||||
|         self.header(::header::Authorization(::header::Basic{ |         self.header(::header::Authorization(::header::Basic{ | ||||||
|             username: username.into(), |             username: username.into(), | ||||||
| @@ -458,13 +461,13 @@ impl RequestBuilder { | |||||||
|                 StatusCode::SeeOther => { |                 StatusCode::SeeOther => { | ||||||
|                     body = None; |                     body = None; | ||||||
|                     match method { |                     match method { | ||||||
|                         Method::Get | Method::Head => {}, |                         Method::Get | Method::Head => {} | ||||||
|                         _ => { |                         _ => { | ||||||
|                             method = Method::Get; |                             method = Method::Get; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     true |                     true | ||||||
|                 }, |                 } | ||||||
|                 StatusCode::TemporaryRedirect | |                 StatusCode::TemporaryRedirect | | ||||||
|                 StatusCode::PermanentRedirect => { |                 StatusCode::PermanentRedirect => { | ||||||
|                     if let Some(ref body) = body { |                     if let Some(ref body) = body { | ||||||
| @@ -472,7 +475,7 @@ impl RequestBuilder { | |||||||
|                     } else { |                     } else { | ||||||
|                         true |                         true | ||||||
|                     } |                     } | ||||||
|                 }, |                 } | ||||||
|                 _ => false, |                 _ => false, | ||||||
|             }; |             }; | ||||||
|  |  | ||||||
| @@ -501,26 +504,26 @@ impl RequestBuilder { | |||||||
|                             redirect::Action::Stop => { |                             redirect::Action::Stop => { | ||||||
|                                 debug!("redirect_policy disallowed redirection to '{}'", loc); |                                 debug!("redirect_policy disallowed redirection to '{}'", loc); | ||||||
|                                 return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); |                                 return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); | ||||||
|                             }, |                             } | ||||||
|                             redirect::Action::LoopDetected => { |                             redirect::Action::LoopDetected => { | ||||||
|                                 return Err(::error::loop_detected(res.url.clone())); |                                 return Err(::error::loop_detected(res.url.clone())); | ||||||
|                             }, |                             } | ||||||
|                             redirect::Action::TooManyRedirects => { |                             redirect::Action::TooManyRedirects => { | ||||||
|                                 return Err(::error::too_many_redirects(res.url.clone())); |                                 return Err(::error::too_many_redirects(res.url.clone())); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     }, |                     } | ||||||
|                     Err(e) => { |                     Err(e) => { | ||||||
|                         debug!("Location header had invalid URI: {:?}", e); |                         debug!("Location header had invalid URI: {:?}", e); | ||||||
|  |  | ||||||
|                         return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))) |                         return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); | ||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|  |  | ||||||
|                 remove_sensitive_headers(&mut headers, &url, &urls); |                 remove_sensitive_headers(&mut headers, &url, &urls); | ||||||
|                 debug!("redirecting to {:?} '{}'", method, url); |                 debug!("redirecting to {:?} '{}'", method, url); | ||||||
|             } else { |             } else { | ||||||
|                 return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))) |                 return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed))); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -551,7 +554,7 @@ fn make_referer(next: &Url, previous: &Url) -> Option<Referer> { | |||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use super::*; |     use super::*; | ||||||
|     use ::body; |     use body; | ||||||
|     use hyper::method::Method; |     use hyper::method::Method; | ||||||
|     use hyper::Url; |     use hyper::Url; | ||||||
|     use hyper::header::{Host, Headers, ContentType}; |     use hyper::header::{Host, Headers, ContentType}; | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								src/error.rs
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/error.rs
									
									
									
									
									
								
							| @@ -1,7 +1,7 @@ | |||||||
| use std::error::Error as StdError; | use std::error::Error as StdError; | ||||||
| use std::fmt; | use std::fmt; | ||||||
|  |  | ||||||
| use ::Url; | use Url; | ||||||
|  |  | ||||||
| /// The Errors that may occur when processing a `Request`. | /// The Errors that may occur when processing a `Request`. | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| @@ -153,10 +153,12 @@ impl From<InternalFrom<Error>> for Error { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl<T> From<InternalFrom<T>> for Error | impl<T> From<InternalFrom<T>> for Error | ||||||
| where T: Into<Kind> { | where | ||||||
|  |     T: Into<Kind>, | ||||||
|  | { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn from(other: InternalFrom<T>) -> Error { |     fn from(other: InternalFrom<T>) -> Error { | ||||||
|          Error { |         Error { | ||||||
|             kind: other.0.into(), |             kind: other.0.into(), | ||||||
|             url: other.1, |             url: other.1, | ||||||
|         } |         } | ||||||
| @@ -165,7 +167,9 @@ where T: Into<Kind> { | |||||||
|  |  | ||||||
| #[inline] | #[inline] | ||||||
| pub fn from<T>(err: T) -> Error | pub fn from<T>(err: T) -> Error | ||||||
| where T: Into<Kind> { | where | ||||||
|  |     T: Into<Kind>, | ||||||
|  | { | ||||||
|     InternalFrom(err, None).into() |     InternalFrom(err, None).into() | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -193,6 +197,6 @@ fn test_error_get_ref_downcasts() { | |||||||
|  |  | ||||||
|     match cause { |     match cause { | ||||||
|         &::hyper::Error::Status => (), |         &::hyper::Error::Status => (), | ||||||
|         _ => panic!("unexpected downcast: {:?}", cause) |         _ => panic!("unexpected downcast: {:?}", cause), | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -115,7 +115,8 @@ | |||||||
| //! [serde]: http://serde.rs | //! [serde]: http://serde.rs | ||||||
| extern crate hyper; | extern crate hyper; | ||||||
|  |  | ||||||
| #[macro_use] extern crate log; | #[macro_use] | ||||||
|  | extern crate log; | ||||||
| extern crate libflate; | extern crate libflate; | ||||||
| extern crate hyper_native_tls; | extern crate hyper_native_tls; | ||||||
| extern crate serde; | extern crate serde; | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ use std::fmt; | |||||||
|  |  | ||||||
| use hyper::header::{Headers, Authorization, Cookie}; | use hyper::header::{Headers, Authorization, Cookie}; | ||||||
|  |  | ||||||
| use ::Url; | use Url; | ||||||
|  |  | ||||||
| /// A type that controls the policy on how to handle the following of redirects. | /// A type that controls the policy on how to handle the following of redirects. | ||||||
| /// | /// | ||||||
| @@ -77,7 +77,9 @@ impl RedirectPolicy { | |||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
|     pub fn custom<T>(policy: T) -> RedirectPolicy |     pub fn custom<T>(policy: T) -> RedirectPolicy | ||||||
|     where T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static { |     where | ||||||
|  |         T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static, | ||||||
|  |     { | ||||||
|         RedirectPolicy { |         RedirectPolicy { | ||||||
|             inner: Policy::Custom(Box::new(policy)), |             inner: Policy::Custom(Box::new(policy)), | ||||||
|         } |         } | ||||||
| @@ -94,7 +96,7 @@ impl RedirectPolicy { | |||||||
|                 } else { |                 } else { | ||||||
|                     attempt.follow() |                     attempt.follow() | ||||||
|                 } |                 } | ||||||
|             }, |             } | ||||||
|             Policy::None => attempt.stop(), |             Policy::None => attempt.stop(), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -262,7 +264,7 @@ fn test_remove_sensitive_headers() { | |||||||
|         ]) |         ]) | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     let next  = Url::parse("http://initial-domain.com/path").unwrap(); |     let next = Url::parse("http://initial-domain.com/path").unwrap(); | ||||||
|     let mut prev = vec![Url::parse("http://initial-domain.com/new_path").unwrap()]; |     let mut prev = vec![Url::parse("http://initial-domain.com/new_path").unwrap()]; | ||||||
|     let mut filtered_headers = headers.clone(); |     let mut filtered_headers = headers.clone(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ pub struct Response { | |||||||
| pub fn new(res: ::hyper::client::Response, gzip: bool) -> Response { | pub fn new(res: ::hyper::client::Response, gzip: bool) -> Response { | ||||||
|     info!("Response: '{}' for {}", res.status, res.url); |     info!("Response: '{}' for {}", res.status, res.url); | ||||||
|     Response { |     Response { | ||||||
|         inner: Decoder::from_hyper_response(res, gzip) |         inner: Decoder::from_hyper_response(res, gzip), | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -32,8 +32,8 @@ impl fmt::Debug for Response { | |||||||
|                     .field("headers", &hyper_response.headers) |                     .field("headers", &hyper_response.headers) | ||||||
|                     .field("version", &hyper_response.version) |                     .field("version", &hyper_response.version) | ||||||
|                     .finish() |                     .finish() | ||||||
|             }, |             } | ||||||
|             Decoder::Gzip{ ref head, .. } | |             Decoder::Gzip { ref head, .. } | | ||||||
|             Decoder::Errored { ref head, .. } => { |             Decoder::Errored { ref head, .. } => { | ||||||
|                 f.debug_struct("Response") |                 f.debug_struct("Response") | ||||||
|                     .field("url", &head.url) |                     .field("url", &head.url) | ||||||
| @@ -52,7 +52,7 @@ impl Response { | |||||||
|     pub fn url(&self) -> &Url { |     pub fn url(&self) -> &Url { | ||||||
|         match self.inner { |         match self.inner { | ||||||
|             Decoder::PlainText(ref hyper_response) => &hyper_response.url, |             Decoder::PlainText(ref hyper_response) => &hyper_response.url, | ||||||
|             Decoder::Gzip{ ref head, .. } | |             Decoder::Gzip { ref head, .. } | | ||||||
|             Decoder::Errored { ref head, .. } => &head.url, |             Decoder::Errored { ref head, .. } => &head.url, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -62,7 +62,7 @@ impl Response { | |||||||
|     pub fn status(&self) -> &StatusCode { |     pub fn status(&self) -> &StatusCode { | ||||||
|         match self.inner { |         match self.inner { | ||||||
|             Decoder::PlainText(ref hyper_response) => &hyper_response.status, |             Decoder::PlainText(ref hyper_response) => &hyper_response.status, | ||||||
|             Decoder::Gzip{ ref head, .. } | |             Decoder::Gzip { ref head, .. } | | ||||||
|             Decoder::Errored { ref head, .. } => &head.status, |             Decoder::Errored { ref head, .. } => &head.status, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -72,7 +72,7 @@ impl Response { | |||||||
|     pub fn headers(&self) -> &Headers { |     pub fn headers(&self) -> &Headers { | ||||||
|         match self.inner { |         match self.inner { | ||||||
|             Decoder::PlainText(ref hyper_response) => &hyper_response.headers, |             Decoder::PlainText(ref hyper_response) => &hyper_response.headers, | ||||||
|             Decoder::Gzip{ ref head, .. } | |             Decoder::Gzip { ref head, .. } | | ||||||
|             Decoder::Errored { ref head, .. } => &head.headers, |             Decoder::Errored { ref head, .. } => &head.headers, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -82,7 +82,7 @@ impl Response { | |||||||
|     pub fn version(&self) -> &HttpVersion { |     pub fn version(&self) -> &HttpVersion { | ||||||
|         match self.inner { |         match self.inner { | ||||||
|             Decoder::PlainText(ref hyper_response) => &hyper_response.version, |             Decoder::PlainText(ref hyper_response) => &hyper_response.version, | ||||||
|             Decoder::Gzip{ ref head, .. } | |             Decoder::Gzip { ref head, .. } | | ||||||
|             Decoder::Errored { ref head, .. } => &head.version, |             Decoder::Errored { ref head, .. } => &head.version, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -184,7 +184,7 @@ fn new_gzip(mut res: ::hyper::client::Response) -> Decoder { | |||||||
|         Ok(0) => return Decoder::PlainText(res), |         Ok(0) => return Decoder::PlainText(res), | ||||||
|         Ok(n) => { |         Ok(n) => { | ||||||
|             debug_assert_eq!(n, 1); |             debug_assert_eq!(n, 1); | ||||||
|         }, |         } | ||||||
|         Err(e) => return Decoder::Errored { |         Err(e) => return Decoder::Errored { | ||||||
|             err: Some(e), |             err: Some(e), | ||||||
|             head: Head { |             head: Head { | ||||||
| @@ -193,7 +193,7 @@ fn new_gzip(mut res: ::hyper::client::Response) -> Decoder { | |||||||
|                 url: res.url.clone(), |                 url: res.url.clone(), | ||||||
|                 version: res.version, |                 version: res.version, | ||||||
|             } |             } | ||||||
|         }, |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let head = Head { |     let head = Head { | ||||||
| @@ -274,4 +274,3 @@ impl Read for Response { | |||||||
|         self.inner.read(buf) |         self.inner.read(buf) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,8 @@ | |||||||
| extern crate reqwest; | extern crate reqwest; | ||||||
| extern crate libflate; | extern crate libflate; | ||||||
|  |  | ||||||
| #[macro_use] mod server; | #[macro_use] | ||||||
|  | mod server; | ||||||
|  |  | ||||||
| use std::io::Read; | use std::io::Read; | ||||||
| use std::io::prelude::*; | use std::io::prelude::*; | ||||||
| @@ -395,7 +396,7 @@ fn test_gzip_response() { | |||||||
|     let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap(); |     let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap(); | ||||||
|     match encoder.write(b"test request") { |     match encoder.write(b"test request") { | ||||||
|         Ok(n) => assert!(n > 0, "Failed to write to encoder."), |         Ok(n) => assert!(n > 0, "Failed to write to encoder."), | ||||||
|         _ => panic!("Failed to gzip encode string.") |         _ => panic!("Failed to gzip encode string."), | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     let gzipped_content = encoder.finish().into_result().unwrap(); |     let gzipped_content = encoder.finish().into_result().unwrap(); | ||||||
| @@ -426,7 +427,7 @@ fn test_gzip_response() { | |||||||
|     let mut body = ::std::string::String::new(); |     let mut body = ::std::string::String::new(); | ||||||
|     match res.read_to_string(&mut body) { |     match res.read_to_string(&mut body) { | ||||||
|         Ok(n) => assert!(n > 0, "Failed to write to buffer."), |         Ok(n) => assert!(n > 0, "Failed to write to buffer."), | ||||||
|         _ => panic!("Failed to write to buffer.") |         _ => panic!("Failed to write to buffer."), | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     assert_eq!(body, "test request"); |     assert_eq!(body, "test request"); | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ pub fn spawn(txns: Vec<(Vec<u8>, Vec<u8>)>) -> Server { | |||||||
|  |  | ||||||
|             match (::std::str::from_utf8(&expected), ::std::str::from_utf8(&buf[..n])) { |             match (::std::str::from_utf8(&expected), ::std::str::from_utf8(&buf[..n])) { | ||||||
|                 (Ok(expected), Ok(received)) => assert_eq!(expected, received), |                 (Ok(expected), Ok(received)) => assert_eq!(expected, received), | ||||||
|                 _ => assert_eq!(expected, &buf[..n]) |                 _ => assert_eq!(expected, &buf[..n]), | ||||||
|             } |             } | ||||||
|             socket.write_all(&reply).unwrap(); |             socket.write_all(&reply).unwrap(); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user