Skip to content

Commit

Permalink
Check format to all rs files under src (#1188)
Browse files Browse the repository at this point in the history
fixed-format of all missing files.
Fixes #1186
  • Loading branch information
CfirTsabari authored Mar 2, 2021
1 parent 9fa58e3 commit a856638
Show file tree
Hide file tree
Showing 20 changed files with 334 additions and 304 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
command: fmt
args: -- --check

- name: temporary workaround - fmt all files under src
# Workaround for rust-lang/cargo#7732
run: cargo fmt -- --check $(find . -name '*.rs' -print)

build:
name: ${{ matrix.name }}
needs: [style]
Expand Down
118 changes: 64 additions & 54 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#[cfg(any(
feature = "native-tls",
feature = "__rustls",
))]
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
use std::any::Any;
use std::convert::TryInto;
use std::net::IpAddr;
Expand All @@ -21,13 +18,13 @@ use http::Uri;
use hyper::client::ResponseFuture;
#[cfg(feature = "native-tls-crate")]
use native_tls_crate::TlsConnector;
use pin_project_lite::pin_project;
#[cfg(feature = "rustls-tls-native-roots")]
use rustls::RootCertStore;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::time::Sleep;
use pin_project_lite::pin_project;

use log::debug;

Expand Down Expand Up @@ -232,7 +229,6 @@ impl ClientBuilder {
}
}


Connector::new_default_tls(
http,
tls,
Expand All @@ -241,27 +237,25 @@ impl ClientBuilder {
config.local_address,
config.nodelay,
)?
},
}
#[cfg(feature = "native-tls")]
TlsBackend::BuiltNativeTls(conn) => {
Connector::from_built_default_tls(
http,
conn,
proxies.clone(),
user_agent(&config.headers),
config.local_address,
config.nodelay)
},
TlsBackend::BuiltNativeTls(conn) => Connector::from_built_default_tls(
http,
conn,
proxies.clone(),
user_agent(&config.headers),
config.local_address,
config.nodelay,
),
#[cfg(feature = "__rustls")]
TlsBackend::BuiltRustls(conn) => {
Connector::new_rustls_tls(
http,
conn,
proxies.clone(),
user_agent(&config.headers),
config.local_address,
config.nodelay)
},
TlsBackend::BuiltRustls(conn) => Connector::new_rustls_tls(
http,
conn,
proxies.clone(),
user_agent(&config.headers),
config.local_address,
config.nodelay,
),
#[cfg(feature = "__rustls")]
TlsBackend::Rustls => {
use crate::tls::NoVerifier;
Expand All @@ -274,8 +268,8 @@ impl ClientBuilder {
}
#[cfg(feature = "rustls-tls-webpki-roots")]
if config.tls_built_in_root_certs {
tls.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
tls.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
}
#[cfg(feature = "rustls-tls-native-roots")]
if config.tls_built_in_root_certs {
Expand Down Expand Up @@ -304,16 +298,13 @@ impl ClientBuilder {
config.local_address,
config.nodelay,
)
},
#[cfg(any(
feature = "native-tls",
feature = "__rustls",
))]
}
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
TlsBackend::UnknownPreconfigured => {
return Err(crate::error::builder(
"Unknown TLS backend passed to `use_preconfigured_tls`"
"Unknown TLS backend passed to `use_preconfigured_tls`",
));
},
}
}

#[cfg(not(feature = "__tls"))]
Expand Down Expand Up @@ -740,8 +731,8 @@ impl ClientBuilder {
///
/// If `None`, the option will not be set.
pub fn tcp_keepalive<D>(mut self, val: D) -> ClientBuilder
where
D: Into<Option<Duration>>,
where
D: Into<Option<Duration>>,
{
self.config.tcp_keepalive = val.into();
self
Expand All @@ -759,7 +750,14 @@ impl ClientBuilder {
/// This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)`
/// feature to be enabled.
#[cfg(feature = "__tls")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "default-tls", feature = "native-tls", feature = "rustls-tls"))))]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "default-tls",
feature = "native-tls",
feature = "rustls-tls"
)))
)]
pub fn add_root_certificate(mut self, cert: Certificate) -> ClientBuilder {
self.config.root_certs.push(cert);
self
Expand All @@ -774,11 +772,15 @@ impl ClientBuilder {
/// This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)`
/// feature to be enabled.
#[cfg(feature = "__tls")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "default-tls", feature = "native-tls", feature = "rustls-tls"))))]
pub fn tls_built_in_root_certs(
mut self,
tls_built_in_root_certs: bool,
) -> ClientBuilder {
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "default-tls",
feature = "native-tls",
feature = "rustls-tls"
)))
)]
pub fn tls_built_in_root_certs(mut self, tls_built_in_root_certs: bool) -> ClientBuilder {
self.config.tls_built_in_root_certs = tls_built_in_root_certs;
self
}
Expand Down Expand Up @@ -837,7 +839,14 @@ impl ClientBuilder {
/// This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)`
/// feature to be enabled.
#[cfg(feature = "__tls")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "default-tls", feature = "native-tls", feature = "rustls-tls"))))]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "default-tls",
feature = "native-tls",
feature = "rustls-tls"
)))
)]
pub fn danger_accept_invalid_certs(mut self, accept_invalid_certs: bool) -> ClientBuilder {
self.config.certs_verification = !accept_invalid_certs;
self
Expand Down Expand Up @@ -891,16 +900,15 @@ impl ClientBuilder {
///
/// This requires one of the optional features `native-tls` or
/// `rustls-tls(-...)` to be enabled.
#[cfg(any(
feature = "native-tls",
feature = "__rustls",
))]
#[cfg(any(feature = "native-tls", feature = "__rustls",))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "native-tls", feature = "rustls-tls"))))]
pub fn use_preconfigured_tls(mut self, tls: impl Any) -> ClientBuilder {
let mut tls = Some(tls);
#[cfg(feature = "native-tls")]
{
if let Some(conn) = (&mut tls as &mut dyn Any).downcast_mut::<Option<native_tls_crate::TlsConnector>>() {
if let Some(conn) =
(&mut tls as &mut dyn Any).downcast_mut::<Option<native_tls_crate::TlsConnector>>()
{
let tls = conn.take().expect("is definitely Some");
let tls = crate::tls::TlsBackend::BuiltNativeTls(tls);
self.config.tls = tls;
Expand All @@ -909,8 +917,9 @@ impl ClientBuilder {
}
#[cfg(feature = "__rustls")]
{
if let Some(conn) = (&mut tls as &mut dyn Any).downcast_mut::<Option<rustls::ClientConfig>>() {

if let Some(conn) =
(&mut tls as &mut dyn Any).downcast_mut::<Option<rustls::ClientConfig>>()
{
let tls = conn.take().expect("is definitely Some");
let tls = crate::tls::TlsBackend::BuiltRustls(tls);
self.config.tls = tls;
Expand Down Expand Up @@ -955,7 +964,7 @@ impl ClientBuilder {
}

/// Restrict the Client to be used with HTTPS only requests.
///
///
/// Defaults to false.
pub fn https_only(mut self, enabled: bool) -> ClientBuilder {
self.config.https_only = enabled;
Expand Down Expand Up @@ -1428,8 +1437,8 @@ impl Future for PendingRequest {
.map(|cookie| cookie.into_inner().into_owned())
.peekable();
if cookies.peek().is_some() {
let mut store = store_wrapper.write().unwrap();
store.0.store_response_cookies(cookies, &self.url);
let mut store = store_wrapper.write().unwrap();
store.0.store_response_cookies(cookies, &self.url);
}
}
}
Expand Down Expand Up @@ -1600,7 +1609,8 @@ fn add_cookie_header(headers: &mut HeaderMap, cookie_store: &cookie::CookieStore

#[cfg(feature = "rustls-tls-native-roots")]
lazy_static! {
static ref NATIVE_ROOTS: std::io::Result<RootCertStore> = rustls_native_certs::load_native_certs().map_err(|e| e.1);
static ref NATIVE_ROOTS: std::io::Result<RootCertStore> =
rustls_native_certs::load_native_certs().map_err(|e| e.1);
}

#[cfg(test)]
Expand Down
20 changes: 11 additions & 9 deletions src/async_impl/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use futures_util::stream::Peekable;
use http::HeaderMap;
use hyper::body::HttpBody;

#[cfg(any(feature = "gzip", feature = "brotli"))]
use tokio_util::io::StreamReader;
#[cfg(any(feature = "gzip", feature = "brotli"))]
use tokio_util::codec::{BytesCodec, FramedRead};
#[cfg(any(feature = "gzip", feature = "brotli"))]
use tokio_util::io::StreamReader;

use super::super::Body;
use crate::error;
Expand Down Expand Up @@ -190,11 +190,7 @@ impl Decoder {
/// how to decode the content body of the request.
///
/// Uses the correct variant by inspecting the Content-Encoding header.
pub(super) fn detect(
_headers: &mut HeaderMap,
body: Body,
_accepts: Accepts,
) -> Decoder {
pub(super) fn detect(_headers: &mut HeaderMap, body: Body, _accepts: Accepts) -> Decoder {
#[cfg(feature = "gzip")]
{
if _accepts.gzip && Decoder::detect_gzip(_headers) {
Expand Down Expand Up @@ -307,9 +303,15 @@ impl Future for Pending {

match self.1 {
#[cfg(feature = "brotli")]
DecoderType::Brotli => Poll::Ready(Ok(Inner::Brotli(FramedRead::new(BrotliDecoder::new(StreamReader::new(_body)), BytesCodec::new())))),
DecoderType::Brotli => Poll::Ready(Ok(Inner::Brotli(FramedRead::new(
BrotliDecoder::new(StreamReader::new(_body)),
BytesCodec::new(),
)))),
#[cfg(feature = "gzip")]
DecoderType::Gzip => Poll::Ready(Ok(Inner::Gzip(FramedRead::new(GzipDecoder::new(StreamReader::new(_body)), BytesCodec::new())))),
DecoderType::Gzip => Poll::Ready(Ok(Inner::Gzip(FramedRead::new(
GzipDecoder::new(StreamReader::new(_body)),
BytesCodec::new(),
)))),
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/async_impl/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,10 @@ mod tests {
fn form_empty() {
let form = Form::new();

let rt = runtime::Builder::new_current_thread().enable_all().build().expect("new rt");
let rt = runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("new rt");
let body = form.stream().into_stream();
let s = body.map_ok(|try_c| try_c.to_vec()).try_concat();

Expand Down Expand Up @@ -568,7 +571,10 @@ mod tests {
--boundary\r\n\
Content-Disposition: form-data; name=\"key3\"; filename=\"filename\"\r\n\r\n\
value3\r\n--boundary--\r\n";
let rt = runtime::Builder::new_current_thread().enable_all().build().expect("new rt");
let rt = runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("new rt");
let body = form.stream().into_stream();
let s = body.map(|try_c| try_c.map(|r| r.to_vec())).try_concat();

Expand All @@ -595,7 +601,10 @@ mod tests {
\r\n\
value2\r\n\
--boundary--\r\n";
let rt = runtime::Builder::new_current_thread().enable_all().build().expect("new rt");
let rt = runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("new rt");
let body = form.stream().into_stream();
let s = body.map(|try_c| try_c.map(|r| r.to_vec())).try_concat();

Expand Down
Loading

0 comments on commit a856638

Please sign in to comment.