Some slightly less trivial rustfmt changes.

This commit is contained in:
Tom Prince
2017-05-31 14:48:37 -06:00
parent 4c60e6d35f
commit a2c24a4009
7 changed files with 78 additions and 72 deletions

View File

@@ -21,7 +21,8 @@ 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"));
static DEFAULT_USER_AGENT: &'static str =
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
/// A `Client` to make Requests with.
///
@@ -74,9 +75,8 @@ impl Certificate {
///
/// If the provided buffer is not valid DER, an error will be returned.
pub fn from_der(der: &[u8]) -> ::Result<Certificate> {
let inner = try_!(
native_tls::Certificate::from_der(der)
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
let inner = try_!(native_tls::Certificate::from_der(der)
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
Ok(Certificate(inner))
}
}
@@ -119,9 +119,8 @@ struct Config {
impl ClientBuilder {
/// Constructs a new `ClientBuilder`
pub fn new() -> ::Result<ClientBuilder> {
let tls_connector_builder = try_!(
native_tls::TlsConnector::builder()
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
let tls_connector_builder = try_!(native_tls::TlsConnector::builder()
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
Ok(ClientBuilder {
config: Some(Config {
hostname_verification: true,
@@ -139,8 +138,10 @@ impl ClientBuilder {
pub fn build(&mut self) -> ::Result<Client> {
let config = self.take_config();
let tls_connector = try_!(
config.tls.build().map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
let tls_connector = try_!(config
.tls
.build()
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
let mut tls_client = NativeTlsClient::from(tls_connector);
if !config.hostname_verification {
tls_client.danger_disable_hostname_verification(true);
@@ -149,7 +150,9 @@ impl ClientBuilder {
let mut hyper_client = ::hyper::Client::with_connector(
::hyper::client::Pool::with_connector(
Default::default(),
::hyper::net::HttpsConnector::new(tls_client)));
::hyper::net::HttpsConnector::new(tls_client),
)
);
hyper_client.set_redirect_policy(::hyper::client::RedirectPolicy::FollowNone);
@@ -168,8 +171,10 @@ impl ClientBuilder {
/// This can be used to connect to a server that has a self-signed
/// certificate for example.
pub fn add_root_certificate(&mut self, cert: Certificate) -> ::Result<&mut ClientBuilder> {
try_!(self.config_mut().tls.add_root_certificate(cert.0)
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
try_!(self.config_mut()
.tls
.add_root_certificate(cert.0)
.map_err(|e| ::hyper::Error::Ssl(Box::new(e))));
Ok(self)
}
@@ -192,11 +197,15 @@ impl ClientBuilder {
// private
fn config_mut(&mut self) -> &mut Config {
self.config.as_mut().expect("ClientBuilder cannot be reused after building a Client")
self.config
.as_mut()
.expect("ClientBuilder cannot be reused after building a Client")
}
fn take_config(&mut self) -> Config {
self.config.take().expect("ClientBuilder cannot be reused after building a Client")
self.config
.take()
.expect("ClientBuilder cannot be reused after building a Client")
}
}
@@ -497,7 +506,8 @@ impl RequestBuilder {
}
}
urls.push(url);
let action = check_redirect(&client.redirect_policy.lock().unwrap(), &loc, &urls);
let action =
check_redirect(&client.redirect_policy.lock().unwrap(), &loc, &urls);
match action {
redirect::Action::Follow => loc,
@@ -688,7 +698,8 @@ mod tests {
r = r.form(&form_data);
// Make sure the content type was set
assert_eq!(r.headers.get::<ContentType>(), Some(&ContentType::form_url_encoded()));
assert_eq!(r.headers.get::<ContentType>(),
Some(&ContentType::form_url_encoded()));
let buf = body::read_to_string(r.body.unwrap().unwrap()).unwrap();

View File

@@ -192,8 +192,10 @@ pub fn too_many_redirects(url: Url) -> Error {
#[test]
fn test_error_get_ref_downcasts() {
let err: Error = from(::hyper::Error::Status);
let cause = err.get_ref().unwrap()
.downcast_ref::<::hyper::Error>().unwrap();
let cause = err.get_ref()
.unwrap()
.downcast_ref::<::hyper::Error>()
.unwrap();
match cause {
&::hyper::Error::Status => (),

View File

@@ -189,8 +189,8 @@ pub fn check_redirect(policy: &RedirectPolicy, next: &Url, previous: &[Url]) ->
pub fn remove_sensitive_headers(headers: &mut Headers, next: &Url, previous: &[Url]) {
if let Some(previous) = previous.last() {
let cross_host = next.host_str() != previous.host_str()
|| next.port_or_known_default() != previous.port_or_known_default();
let cross_host = next.host_str() != previous.host_str() ||
next.port_or_known_default() != previous.port_or_known_default();
if cross_host {
headers.remove::<Authorization<String>>();
headers.remove::<Cookie>();
@@ -231,7 +231,8 @@ fn test_redirect_policy_limit() {
previous.push(Url::parse("http://a.b.d/e/33").unwrap());
assert_eq!(check_redirect(&policy, &next, &previous), Action::TooManyRedirects);
assert_eq!(check_redirect(&policy, &next, &previous),
Action::TooManyRedirects);
}
#[test]
@@ -258,11 +259,7 @@ fn test_remove_sensitive_headers() {
let mut headers = Headers::new();
headers.set(Accept::star());
headers.set(Authorization("let me in".to_owned()));
headers.set(
Cookie(vec![
String::from("foo=bar")
])
);
headers.set(Cookie(vec![String::from("foo=bar")]));
let next = Url::parse("http://initial-domain.com/path").unwrap();
let mut prev = vec![Url::parse("http://initial-domain.com/new_path").unwrap()];

View File

@@ -148,12 +148,13 @@ impl Decoder {
}
let content_encoding_gzip: bool;
let mut is_gzip = {
content_encoding_gzip = res.headers.get::<ContentEncoding>().map_or(false, |encs|{
encs.contains(&Encoding::Gzip)
});
content_encoding_gzip || res.headers.get::<TransferEncoding>().map_or(false, |encs|{
encs.contains(&Encoding::Gzip)
})
content_encoding_gzip = res.headers
.get::<ContentEncoding>()
.map_or(false, |encs| encs.contains(&Encoding::Gzip));
content_encoding_gzip ||
res.headers
.get::<TransferEncoding>()
.map_or(false, |encs| encs.contains(&Encoding::Gzip))
};
if is_gzip {
if let Some(content_length) = res.headers.get::<ContentLength>() {
@@ -249,12 +250,8 @@ impl Read for Peeked {
impl Read for Decoder {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match *self {
Decoder::PlainText(ref mut hyper_response) => {
hyper_response.read(buf)
},
Decoder::Gzip{ref mut decoder, ..} => {
decoder.read(buf)
},
Decoder::PlainText(ref mut hyper_response) => hyper_response.read(buf),
Decoder::Gzip { ref mut decoder, .. } => decoder.read(buf),
Decoder::Errored { ref mut err, .. } => {
Err(err.take().unwrap_or_else(previously_errored))
}