1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

change rustfmt line width to 96

This commit is contained in:
Rob Ede
2021-02-11 23:03:17 +00:00
parent c1af5089b9
commit 31d9ed81c5
56 changed files with 463 additions and 756 deletions

View File

@ -82,8 +82,7 @@ where
let connection = fut.await?;
// send request
let (head, framed) =
connection.open_tunnel(RequestHeadType::from(head)).await?;
let (head, framed) = connection.open_tunnel(RequestHeadType::from(head)).await?;
let framed = framed.into_map_io(|io| BoxedSocket(Box::new(Socket(io))));
Ok((head, framed))
@ -142,10 +141,7 @@ impl AsyncWrite for BoxedSocket {
Pin::new(self.get_mut().0.as_write()).poll_flush(cx)
}
fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<io::Result<()>> {
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Pin::new(self.get_mut().0.as_write()).poll_shutdown(cx)
}
}

View File

@ -1,7 +1,5 @@
//! Http client errors
pub use actix_http::client::{
ConnectError, FreezeRequestError, InvalidUrl, SendRequestError,
};
pub use actix_http::client::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
pub use actix_http::error::PayloadError;
pub use actix_http::http::Error as HttpError;
pub use actix_http::ws::HandshakeError as WsHandshakeError;

View File

@ -11,8 +11,7 @@ use actix_http::body::Body;
use actix_http::cookie::{Cookie, CookieJar};
use actix_http::http::header::{self, IntoHeaderPair};
use actix_http::http::{
uri, ConnectionType, Error as HttpError, HeaderMap, HeaderValue, Method, Uri,
Version,
uri, ConnectionType, Error as HttpError, HeaderMap, HeaderValue, Method, Uri, Version,
};
use actix_http::{Error, RequestHead};
@ -520,15 +519,11 @@ impl ClientRequest {
.unwrap_or(true);
if https {
slf =
slf.insert_header_if_none((header::ACCEPT_ENCODING, HTTPS_ENCODING))
slf = slf.insert_header_if_none((header::ACCEPT_ENCODING, HTTPS_ENCODING))
} else {
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
{
slf = slf.insert_header_if_none((
header::ACCEPT_ENCODING,
"gzip, deflate",
))
slf = slf.insert_header_if_none((header::ACCEPT_ENCODING, "gzip, deflate"))
}
};
}

View File

@ -50,8 +50,7 @@ impl<S> HttpMessage for ClientResponse<S> {
if self.extensions().get::<Cookies>().is_none() {
let mut cookies = Vec::new();
for hdr in self.headers().get_all(&SET_COOKIE) {
let s = std::str::from_utf8(hdr.as_bytes())
.map_err(CookieParseError::from)?;
let s = std::str::from_utf8(hdr.as_bytes()).map_err(CookieParseError::from)?;
cookies.push(Cookie::parse_encoded(s)?.into_owned());
}
self.extensions_mut().insert(Cookies(cookies));
@ -132,10 +131,7 @@ where
{
type Item = Result<Bytes, PayloadError>;
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Pin::new(&mut self.get_mut().payload).poll_next(cx)
}
}
@ -306,9 +302,7 @@ where
if let Some(len) = self.length.take() {
if len > self.fut.as_ref().unwrap().limit {
return Poll::Ready(Err(JsonPayloadError::Payload(
PayloadError::Overflow,
)));
return Poll::Ready(Err(JsonPayloadError::Payload(PayloadError::Overflow)));
}
}
@ -374,8 +368,7 @@ mod tests {
_ => unreachable!("error"),
}
let mut req =
TestResponse::with_header(header::CONTENT_LENGTH, "1000000").finish();
let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "1000000").finish();
match req.body().await.err().unwrap() {
PayloadError::Overflow => {}
_ => unreachable!("error"),

View File

@ -81,8 +81,7 @@ impl SendClientRequest {
#[cfg(feature = "compress")]
impl Future for SendClientRequest {
type Output =
Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
@ -99,15 +98,9 @@ impl Future for SendClientRequest {
let res = futures_core::ready!(Pin::new(send).poll(cx)).map(|res| {
res.map_body(|head, payload| {
if *response_decompress {
Payload::Stream(Decoder::from_headers(
payload,
&head.headers,
))
Payload::Stream(Decoder::from_headers(payload, &head.headers))
} else {
Payload::Stream(Decoder::new(
payload,
ContentEncoding::Identity,
))
Payload::Stream(Decoder::new(payload, ContentEncoding::Identity))
}
})
});
@ -189,11 +182,11 @@ impl RequestSender {
B: Into<Body>,
{
let fut = match self {
RequestSender::Owned(head) => config.connector.send_request(
RequestHeadType::Owned(head),
body.into(),
addr,
),
RequestSender::Owned(head) => {
config
.connector
.send_request(RequestHeadType::Owned(head), body.into(), addr)
}
RequestSender::Rc(head, extra_headers) => config.connector.send_request(
RequestHeadType::Rc(head, extra_headers),
body.into(),
@ -217,8 +210,7 @@ impl RequestSender {
Err(e) => return Error::from(e).into(),
};
if let Err(e) = self.set_header_if_none(header::CONTENT_TYPE, "application/json")
{
if let Err(e) = self.set_header_if_none(header::CONTENT_TYPE, "application/json") {
return e.into();
}
@ -245,10 +237,9 @@ impl RequestSender {
};
// set content-type
if let Err(e) = self.set_header_if_none(
header::CONTENT_TYPE,
"application/x-www-form-urlencoded",
) {
if let Err(e) =
self.set_header_if_none(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
{
return e.into();
}
@ -292,11 +283,7 @@ impl RequestSender {
self.send_body(addr, response_decompress, timeout, config, Body::Empty)
}
fn set_header_if_none<V>(
&mut self,
key: HeaderName,
value: V,
) -> Result<(), HttpError>
fn set_header_if_none<V>(&mut self, key: HeaderName, value: V) -> Result<(), HttpError>
where
V: IntoHeaderValue,
{

View File

@ -40,12 +40,8 @@ pub use actix_http::ws::{CloseCode, CloseReason, Codec, Frame, Message};
use crate::connect::BoxedSocket;
use crate::error::{InvalidUrl, SendRequestError, WsClientError};
use crate::http::header::{
self, HeaderName, HeaderValue, IntoHeaderValue, AUTHORIZATION,
};
use crate::http::{
ConnectionType, Error as HttpError, Method, StatusCode, Uri, Version,
};
use crate::http::header::{self, HeaderName, HeaderValue, IntoHeaderValue, AUTHORIZATION};
use crate::http::{ConnectionType, Error as HttpError, Method, StatusCode, Uri, Version};
use crate::response::ClientResponse;
use crate::ClientConfig;

View File

@ -51,8 +51,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
#[actix_rt::test]
async fn test_simple() {
let srv = test::start(|| {
App::new()
.service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))))
App::new().service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))))
});
let request = srv.get("/").insert_header(("x-test", "111")).send();
@ -612,9 +611,8 @@ async fn test_client_streaming_explicit() {
}))
});
let body = stream::once(async {
Ok::<_, actix_http::Error>(Bytes::from_static(STR.as_bytes()))
});
let body =
stream::once(async { Ok::<_, actix_http::Error>(Bytes::from_static(STR.as_bytes())) });
let req = srv.post("/").send_stream(Box::pin(body));
let mut res = req.await.unwrap();

View File

@ -64,8 +64,7 @@ async fn test_connection_reuse_h2() {
.and_then(
HttpService::build()
.h2(map_config(
App::new()
.service(web::resource("/").route(web::to(HttpResponse::Ok))),
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))),
|_| AppConfig::default(),
))
.rustls(tls_config())

View File

@ -48,8 +48,7 @@ async fn test_connection_reuse_h2() {
.and_then(
HttpService::build()
.h2(map_config(
App::new()
.service(web::resource("/").route(web::to(HttpResponse::Ok))),
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))),
|_| AppConfig::default(),
))
.openssl(ssl_acceptor())