update and tidy code

This commit is contained in:
Daniel Eades
2019-08-07 20:44:24 +01:00
committed by Sean McArthur
parent 86d9cbc66e
commit 5dc5162765
14 changed files with 46 additions and 55 deletions

View File

@@ -42,7 +42,7 @@ use crate::{Certificate, Identity};
#[cfg(feature = "tls")]
use crate::tls::TlsBackend;
static DEFAULT_USER_AGENT: &'static str =
static DEFAULT_USER_AGENT: &str =
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
/// An asynchronous `Client` to make Requests with.
@@ -101,7 +101,7 @@ impl ClientBuilder {
ClientBuilder {
config: Config {
gzip: true,
headers: headers,
headers,
#[cfg(feature = "default-tls")]
hostname_verification: true,
#[cfg(feature = "tls")]
@@ -338,7 +338,7 @@ impl ClientBuilder {
pub fn use_sys_proxy(mut self) -> ClientBuilder {
let proxies = get_proxies();
self.config.proxies.push(Proxy::custom(move |url| {
return if proxies.contains_key(url.scheme()) {
if proxies.contains_key(url.scheme()) {
Some((*proxies.get(url.scheme()).unwrap()).clone())
} else {
None
@@ -610,16 +610,16 @@ impl Client {
Pending {
inner: PendingInner::Request(PendingRequest {
method: method,
url: url,
headers: headers,
method,
url,
headers,
body: reusable,
urls: Vec::new(),
client: self.inner.clone(),
in_flight: in_flight,
in_flight,
timeout,
}),
}
@@ -644,14 +644,11 @@ impl Client {
for proxy in self.inner.proxies.iter() {
if proxy.is_match(dst) {
match proxy.http_basic_auth(dst) {
Some(header) => {
headers.insert(
PROXY_AUTHORIZATION,
header,
);
},
None => (),
if let Some(header) = proxy.http_basic_auth(dst) {
headers.insert(
PROXY_AUTHORIZATION,
header,
);
}
break;

View File

@@ -117,12 +117,12 @@ impl Decoder {
content_encoding_gzip = headers
.get_all(CONTENT_ENCODING)
.iter()
.fold(false, |acc, enc| acc || enc == "gzip");
.any(|enc| enc == "gzip");
content_encoding_gzip ||
headers
.get_all(TRANSFER_ENCODING)
.iter()
.fold(false, |acc, enc| acc || enc == "gzip")
.any(|enc| enc == "gzip")
};
if is_gzip {
if let Some(content_length) = headers.get(CONTENT_LENGTH) {
@@ -264,7 +264,7 @@ impl<S> ReadableChunks<S> {
pub(crate) fn new(stream: S) -> Self {
ReadableChunks {
state: ReadState::NotReady,
stream: stream,
stream,
}
}
}

View File

@@ -61,7 +61,7 @@ impl Form {
/// # Examples
///
/// ```
/// let form = reqwest::async::multipart::Form::new()
/// let form = reqwest::r#async::multipart::Form::new()
/// .text("username", "seanmonstar")
/// .text("password", "secret");
/// ```
@@ -98,7 +98,7 @@ impl Form {
/// Consume this instance and transform into an instance of hyper::Body for use in a request.
pub(crate) fn stream(mut self) -> hyper::Body {
if self.inner.fields.len() == 0 {
if self.inner.fields.is_empty(){
return hyper::Body::empty();
}

View File

@@ -201,8 +201,8 @@ impl RequestBuilder {
/// # use futures::future::Future;
///
/// # fn run() -> Result<(), Error> {
/// let client = reqwest::async::Client::new();
/// let form = reqwest::async::multipart::Form::new()
/// let client = reqwest::r#async::Client::new();
/// let form = reqwest::r#async::multipart::Form::new()
/// .text("key3", "value3")
/// .text("key4", "value4");
///

View File

@@ -184,7 +184,7 @@ impl Response {
/// # Example
///
/// ```
/// # use reqwest::async::Response;
/// # use reqwest::r#async::Response;
/// fn on_response(res: Response) {
/// match res.error_for_status() {
/// Ok(_res) => (),
@@ -214,7 +214,7 @@ impl Response {
/// # Example
///
/// ```
/// # use reqwest::async::Response;
/// # use reqwest::r#async::Response;
/// fn on_response(res: &Response) {
/// match res.error_for_status_ref() {
/// Ok(_res) => (),
@@ -263,7 +263,7 @@ impl<T: Into<Body>> From<http::Response<T>> for Response {
status: parts.status,
headers: parts.headers,
url: Box::new(url),
body: body,
body,
version: parts.version,
extensions: parts.extensions,
}
@@ -307,10 +307,7 @@ impl Future for Text {
// a block because of borrow checker
{
let (text, _, _) = self.encoding.decode(&bytes);
match text {
Cow::Owned(s) => return Ok(Async::Ready(s)),
_ => (),
}
if let Cow::Owned(s) = text { return Ok(Async::Ready(s)) }
}
unsafe {
// decoding returned Cow::Borrowed, meaning these bytes
@@ -339,8 +336,8 @@ pub trait ResponseBuilderExt {
/// # use std::error::Error;
/// use url::Url;
/// use http::response::Builder;
/// use reqwest::async::ResponseBuilderExt;
/// # fn main() -> Result<(), Box<Error>> {
/// use reqwest::r#async::ResponseBuilderExt;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let response = Builder::new()
/// .status(200)
/// .url(Url::parse("http://example.com")?)