Check format to all rs files under src (#1188)

fixed-format of all missing files.
Fixes seanmonstar/reqwest#1186
This commit is contained in:
CfirTsabari
2021-03-02 03:06:14 +02:00
committed by GitHub
parent 9fa58e316d
commit a856638316
20 changed files with 336 additions and 306 deletions

View File

@@ -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")