Really trivial rustfmt changes.

This commit is contained in:
Tom Prince
2017-05-31 14:42:50 -06:00
parent 427602fb08
commit 4c60e6d35f
9 changed files with 56 additions and 43 deletions

View File

@@ -1,7 +1,9 @@
//! `cargo run --example response_json`
extern crate reqwest;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate error_chain;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate error_chain;
error_chain! {
foreign_links {

View File

@@ -1,7 +1,8 @@
//! `cargo run --example simple`
extern crate reqwest;
extern crate env_logger;
#[macro_use] extern crate error_chain;
#[macro_use]
extern crate error_chain;
error_chain! {
foreign_links {

View File

@@ -5,11 +5,11 @@ use std::time::Duration;
use hyper::client::IntoUrl;
use hyper::header::{Headers, ContentType, Location, Referer, UserAgent, Accept, Encoding,
AcceptEncoding, Range, qitem};
AcceptEncoding, Range, qitem};
use hyper::method::Method;
use hyper::status::StatusCode;
use hyper::version::HttpVersion;
use hyper::{Url};
use hyper::Url;
use hyper_native_tls::{NativeTlsClient, native_tls};
@@ -17,9 +17,9 @@ use serde::Serialize;
use serde_json;
use serde_urlencoded;
use ::body::{self, Body};
use ::redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers};
use ::response::Response;
use body::{self, Body};
use redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers};
use response::Response;
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
where H: ::header::Header + ::header::HeaderFormat
where
H: ::header::Header + ::header::HeaderFormat,
{
self.headers.set(header);
self
@@ -343,7 +344,9 @@ impl RequestBuilder {
/// Enable HTTP basic authentication.
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{
username: username.into(),
@@ -458,13 +461,13 @@ impl RequestBuilder {
StatusCode::SeeOther => {
body = None;
match method {
Method::Get | Method::Head => {},
Method::Get | Method::Head => {}
_ => {
method = Method::Get;
}
}
true
},
}
StatusCode::TemporaryRedirect |
StatusCode::PermanentRedirect => {
if let Some(ref body) = body {
@@ -472,7 +475,7 @@ impl RequestBuilder {
} else {
true
}
},
}
_ => false,
};
@@ -501,26 +504,26 @@ impl RequestBuilder {
redirect::Action::Stop => {
debug!("redirect_policy disallowed redirection to '{}'", loc);
return Ok(::response::new(res, client.auto_ungzip.load(Ordering::Relaxed)));
},
}
redirect::Action::LoopDetected => {
return Err(::error::loop_detected(res.url.clone()));
},
}
redirect::Action::TooManyRedirects => {
return Err(::error::too_many_redirects(res.url.clone()));
}
}
},
}
Err(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);
debug!("redirecting to {:?} '{}'", method, url);
} 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)]
mod tests {
use super::*;
use ::body;
use body;
use hyper::method::Method;
use hyper::Url;
use hyper::header::{Host, Headers, ContentType};

View File

@@ -1,7 +1,7 @@
use std::error::Error as StdError;
use std::fmt;
use ::Url;
use Url;
/// The Errors that may occur when processing a `Request`.
#[derive(Debug)]
@@ -153,10 +153,12 @@ impl From<InternalFrom<Error>> for Error {
}
impl<T> From<InternalFrom<T>> for Error
where T: Into<Kind> {
where
T: Into<Kind>,
{
#[inline]
fn from(other: InternalFrom<T>) -> Error {
Error {
Error {
kind: other.0.into(),
url: other.1,
}
@@ -165,7 +167,9 @@ where T: Into<Kind> {
#[inline]
pub fn from<T>(err: T) -> Error
where T: Into<Kind> {
where
T: Into<Kind>,
{
InternalFrom(err, None).into()
}
@@ -193,6 +197,6 @@ fn test_error_get_ref_downcasts() {
match cause {
&::hyper::Error::Status => (),
_ => panic!("unexpected downcast: {:?}", cause)
_ => panic!("unexpected downcast: {:?}", cause),
}
}

View File

@@ -115,7 +115,8 @@
//! [serde]: http://serde.rs
extern crate hyper;
#[macro_use] extern crate log;
#[macro_use]
extern crate log;
extern crate libflate;
extern crate hyper_native_tls;
extern crate serde;

View File

@@ -2,7 +2,7 @@ use std::fmt;
use hyper::header::{Headers, Authorization, Cookie};
use ::Url;
use Url;
/// 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
where T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static {
where
T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static,
{
RedirectPolicy {
inner: Policy::Custom(Box::new(policy)),
}
@@ -94,7 +96,7 @@ impl RedirectPolicy {
} else {
attempt.follow()
}
},
}
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 filtered_headers = headers.clone();

View File

@@ -18,7 +18,7 @@ pub struct Response {
pub fn new(res: ::hyper::client::Response, gzip: bool) -> Response {
info!("Response: '{}' for {}", res.status, res.url);
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("version", &hyper_response.version)
.finish()
},
Decoder::Gzip{ ref head, .. } |
}
Decoder::Gzip { ref head, .. } |
Decoder::Errored { ref head, .. } => {
f.debug_struct("Response")
.field("url", &head.url)
@@ -52,7 +52,7 @@ impl Response {
pub fn url(&self) -> &Url {
match self.inner {
Decoder::PlainText(ref hyper_response) => &hyper_response.url,
Decoder::Gzip{ ref head, .. } |
Decoder::Gzip { ref head, .. } |
Decoder::Errored { ref head, .. } => &head.url,
}
}
@@ -62,7 +62,7 @@ impl Response {
pub fn status(&self) -> &StatusCode {
match self.inner {
Decoder::PlainText(ref hyper_response) => &hyper_response.status,
Decoder::Gzip{ ref head, .. } |
Decoder::Gzip { ref head, .. } |
Decoder::Errored { ref head, .. } => &head.status,
}
}
@@ -72,7 +72,7 @@ impl Response {
pub fn headers(&self) -> &Headers {
match self.inner {
Decoder::PlainText(ref hyper_response) => &hyper_response.headers,
Decoder::Gzip{ ref head, .. } |
Decoder::Gzip { ref head, .. } |
Decoder::Errored { ref head, .. } => &head.headers,
}
}
@@ -82,7 +82,7 @@ impl Response {
pub fn version(&self) -> &HttpVersion {
match self.inner {
Decoder::PlainText(ref hyper_response) => &hyper_response.version,
Decoder::Gzip{ ref head, .. } |
Decoder::Gzip { ref head, .. } |
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(n) => {
debug_assert_eq!(n, 1);
},
}
Err(e) => return Decoder::Errored {
err: Some(e),
head: Head {
@@ -193,7 +193,7 @@ fn new_gzip(mut res: ::hyper::client::Response) -> Decoder {
url: res.url.clone(),
version: res.version,
}
},
}
}
let head = Head {
@@ -274,4 +274,3 @@ impl Read for Response {
self.inner.read(buf)
}
}

View File

@@ -1,7 +1,8 @@
extern crate reqwest;
extern crate libflate;
#[macro_use] mod server;
#[macro_use]
mod server;
use std::io::Read;
use std::io::prelude::*;
@@ -395,7 +396,7 @@ fn test_gzip_response() {
let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap();
match encoder.write(b"test request") {
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();
@@ -426,7 +427,7 @@ fn test_gzip_response() {
let mut body = ::std::string::String::new();
match res.read_to_string(&mut body) {
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");

View File

@@ -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])) {
(Ok(expected), Ok(received)) => assert_eq!(expected, received),
_ => assert_eq!(expected, &buf[..n])
_ => assert_eq!(expected, &buf[..n]),
}
socket.write_all(&reply).unwrap();
}