Check format to all rs files under src (#1188)
fixed-format of all missing files. Fixes seanmonstar/reqwest#1186
This commit is contained in:
		| @@ -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; | ||||
| @@ -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; | ||||
|  | ||||
| @@ -232,7 +229,6 @@ impl ClientBuilder { | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|  | ||||
|                     Connector::new_default_tls( | ||||
|                         http, | ||||
|                         tls, | ||||
| @@ -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; | ||||
| @@ -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 { | ||||
| @@ -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"))] | ||||
| @@ -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 | ||||
| @@ -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 | ||||
| @@ -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 | ||||
|     } | ||||
| @@ -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 | ||||
| @@ -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; | ||||
| @@ -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; | ||||
| @@ -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; | ||||
| @@ -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); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| @@ -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)] | ||||
|   | ||||
| @@ -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; | ||||
| @@ -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) { | ||||
| @@ -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(), | ||||
|             )))), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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(); | ||||
|  | ||||
| @@ -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(); | ||||
|  | ||||
| @@ -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(); | ||||
|  | ||||
|   | ||||
| @@ -14,11 +14,11 @@ use super::client::{Client, Pending}; | ||||
| #[cfg(feature = "multipart")] | ||||
| use super::multipart; | ||||
| use super::response::Response; | ||||
| use crate::header::{HeaderMap, HeaderName, HeaderValue, CONTENT_TYPE}; | ||||
| #[cfg(feature = "multipart")] | ||||
| use crate::header::CONTENT_LENGTH; | ||||
| use crate::header::{HeaderMap, HeaderName, HeaderValue, CONTENT_TYPE}; | ||||
| use crate::{Method, Url}; | ||||
| use http::{Request as HttpRequest, request::Parts}; | ||||
| use http::{request::Parts, Request as HttpRequest}; | ||||
|  | ||||
| /// A request which can be executed with `Client::execute()`. | ||||
| pub struct Request { | ||||
| @@ -47,7 +47,7 @@ impl Request { | ||||
|             url, | ||||
|             headers: HeaderMap::new(), | ||||
|             body: None, | ||||
|             timeout: None | ||||
|             timeout: None, | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -154,7 +154,7 @@ impl RequestBuilder { | ||||
|         HeaderName: TryFrom<K>, | ||||
|         <HeaderName as TryFrom<K>>::Error: Into<http::Error>, | ||||
|         HeaderValue: TryFrom<V>, | ||||
|         <HeaderValue as TryFrom<V>>::Error: Into<http::Error>,  | ||||
|         <HeaderValue as TryFrom<V>>::Error: Into<http::Error>, | ||||
|     { | ||||
|         self.header_sensitive(key, value, false) | ||||
|     } | ||||
| @@ -476,7 +476,6 @@ fn fmt_request_fields<'a, 'b>( | ||||
|         .field("headers", &req.headers) | ||||
| } | ||||
|  | ||||
|  | ||||
| /// Check the request URL for a "username:password" type authority, and if | ||||
| /// found, remove it from the URL and return it. | ||||
| pub(crate) fn extract_authority(url: &mut Url) -> Option<(String, Option<String>)> { | ||||
| @@ -494,20 +493,21 @@ pub(crate) fn extract_authority(url: &mut Url) -> Option<(String, Option<String> | ||||
|                 .map(String::from) | ||||
|         }); | ||||
|         if !username.is_empty() || password.is_some() { | ||||
|             url | ||||
|                 .set_username("") | ||||
|             url.set_username("") | ||||
|                 .expect("has_authority means set_username shouldn't fail"); | ||||
|             url | ||||
|                 .set_password(None) | ||||
|             url.set_password(None) | ||||
|                 .expect("has_authority means set_password shouldn't fail"); | ||||
|             return Some((username, password)) | ||||
|             return Some((username, password)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     None | ||||
| } | ||||
|  | ||||
| impl<T> TryFrom<HttpRequest<T>> for Request where T:Into<Body>{ | ||||
| impl<T> TryFrom<HttpRequest<T>> for Request | ||||
| where | ||||
|     T: Into<Body>, | ||||
| { | ||||
|     type Error = crate::Error; | ||||
|  | ||||
|     fn try_from(req: HttpRequest<T>) -> crate::Result<Self> { | ||||
| @@ -518,8 +518,7 @@ impl<T> TryFrom<HttpRequest<T>> for Request where T:Into<Body>{ | ||||
|             headers, | ||||
|             .. | ||||
|         } = parts; | ||||
|         let url = Url::parse(&uri.to_string()) | ||||
|             .map_err(crate::error::builder)?; | ||||
|         let url = Url::parse(&uri.to_string()).map_err(crate::error::builder)?; | ||||
|         Ok(Request { | ||||
|             method, | ||||
|             url, | ||||
| @@ -646,7 +645,8 @@ mod tests { | ||||
|     #[test] | ||||
|     fn try_clone_reusable() { | ||||
|         let client = Client::new(); | ||||
|         let builder = client.post("http://httpbin.org/post") | ||||
|         let builder = client | ||||
|             .post("http://httpbin.org/post") | ||||
|             .header("foo", "bar") | ||||
|             .body("from a &str!"); | ||||
|         let req = builder | ||||
| @@ -676,14 +676,11 @@ mod tests { | ||||
|     #[test] | ||||
|     #[cfg(feature = "stream")] | ||||
|     fn try_clone_stream() { | ||||
|         let chunks: Vec<Result<_, ::std::io::Error>> = vec![ | ||||
|             Ok("hello"), | ||||
|             Ok(" "), | ||||
|             Ok("world"), | ||||
|         ]; | ||||
|         let chunks: Vec<Result<_, ::std::io::Error>> = vec![Ok("hello"), Ok(" "), Ok("world")]; | ||||
|         let stream = futures_util::stream::iter(chunks); | ||||
|         let client = Client::new(); | ||||
|         let builder = client.get("http://httpbin.org/get") | ||||
|         let builder = client | ||||
|             .get("http://httpbin.org/get") | ||||
|             .body(super::Body::wrap_stream(stream)); | ||||
|         let clone = builder.try_clone(); | ||||
|         assert!(clone.is_none()); | ||||
| @@ -694,13 +691,13 @@ mod tests { | ||||
|         let client = Client::new(); | ||||
|         let some_url = "https://Aladdin:open sesame@localhost/"; | ||||
|  | ||||
|         let req = client | ||||
|             .get(some_url) | ||||
|             .build() | ||||
|             .expect("request build"); | ||||
|         let req = client.get(some_url).build().expect("request build"); | ||||
|  | ||||
|         assert_eq!(req.url().as_str(), "https://localhost/"); | ||||
|         assert_eq!(req.headers()["authorization"], "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); | ||||
|         assert_eq!( | ||||
|             req.headers()["authorization"], | ||||
|             "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     #[test] | ||||
| @@ -715,7 +712,10 @@ mod tests { | ||||
|             .expect("request build"); | ||||
|  | ||||
|         assert_eq!(req.url().as_str(), "https://localhost/"); | ||||
|         assert_eq!(req.headers()["authorization"], "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); | ||||
|         assert_eq!( | ||||
|             req.headers()["authorization"], | ||||
|             "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" | ||||
|         ); | ||||
|         assert_eq!(req.headers()["authorization"].is_sensitive(), true); | ||||
|     } | ||||
|  | ||||
| @@ -735,11 +735,10 @@ mod tests { | ||||
|         assert_eq!(req.headers()["authorization"].is_sensitive(), true); | ||||
|     } | ||||
|  | ||||
|      | ||||
|  | ||||
|     #[test] | ||||
|     fn convert_from_http_request() { | ||||
|         let http_request = HttpRequest::builder().method("GET") | ||||
|         let http_request = HttpRequest::builder() | ||||
|             .method("GET") | ||||
|             .uri("http://localhost/") | ||||
|             .header("User-Agent", "my-awesome-agent/1.0") | ||||
|             .body("test test test") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user