mirror of
https://github.com/actix/actix-web.git
synced 2024-11-20 08:31:09 +00:00
fmt & clippy
This commit is contained in:
parent
45d2fd4299
commit
60b7aebd0a
15 changed files with 95 additions and 62 deletions
|
@ -66,7 +66,7 @@ hashbrown = "0.5.0"
|
|||
h2 = "0.1.16"
|
||||
http = "0.1.17"
|
||||
httparse = "1.3"
|
||||
indexmap = "1.0"
|
||||
indexmap = "1.2"
|
||||
lazy_static = "1.0"
|
||||
language-tags = "0.2"
|
||||
log = "0.4"
|
||||
|
|
|
@ -147,4 +147,4 @@ impl From<FreezeRequestError> for SendRequestError {
|
|||
FreezeRequestError::Http(e) => e.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ use futures::{Async, Future, Poll, Sink, Stream};
|
|||
|
||||
use crate::error::PayloadError;
|
||||
use crate::h1;
|
||||
use crate::header::HeaderMap;
|
||||
use crate::http::header::{IntoHeaderValue, HOST};
|
||||
use crate::message::{RequestHeadType, ResponseHead};
|
||||
use crate::payload::{Payload, PayloadStream};
|
||||
use crate::header::HeaderMap;
|
||||
|
||||
use super::connection::{ConnectionLifetime, ConnectionType, IoConnection};
|
||||
use super::error::{ConnectError, SendRequestError};
|
||||
|
@ -30,7 +30,9 @@ where
|
|||
B: MessageBody,
|
||||
{
|
||||
// set request host header
|
||||
if !head.as_ref().headers.contains_key(HOST) && !head.extra_headers().iter().any(|h| h.contains_key(HOST)) {
|
||||
if !head.as_ref().headers.contains_key(HOST)
|
||||
&& !head.extra_headers().iter().any(|h| h.contains_key(HOST))
|
||||
{
|
||||
if let Some(host) = head.as_ref().uri.host() {
|
||||
let mut wrt = BytesMut::with_capacity(host.len() + 5).writer();
|
||||
|
||||
|
@ -40,20 +42,16 @@ where
|
|||
};
|
||||
|
||||
match wrt.get_mut().take().freeze().try_into() {
|
||||
Ok(value) => {
|
||||
match head {
|
||||
RequestHeadType::Owned(ref mut head) => {
|
||||
head.headers.insert(HOST, value)
|
||||
},
|
||||
RequestHeadType::Rc(_, ref mut extra_headers) => {
|
||||
let headers = extra_headers.get_or_insert(HeaderMap::new());
|
||||
headers.insert(HOST, value)
|
||||
},
|
||||
Ok(value) => match head {
|
||||
RequestHeadType::Owned(ref mut head) => {
|
||||
head.headers.insert(HOST, value)
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Can not set HOST header {}", e)
|
||||
}
|
||||
RequestHeadType::Rc(_, ref mut extra_headers) => {
|
||||
let headers = extra_headers.get_or_insert(HeaderMap::new());
|
||||
headers.insert(HOST, value)
|
||||
}
|
||||
},
|
||||
Err(e) => log::error!("Can not set HOST header {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING};
|
|||
use http::{request::Request, HttpTryFrom, Method, Version};
|
||||
|
||||
use crate::body::{BodySize, MessageBody};
|
||||
use crate::header::HeaderMap;
|
||||
use crate::message::{RequestHeadType, ResponseHead};
|
||||
use crate::payload::Payload;
|
||||
use crate::header::HeaderMap;
|
||||
|
||||
use super::connection::{ConnectionType, IoConnection};
|
||||
use super::error::SendRequestError;
|
||||
|
@ -69,15 +69,21 @@ where
|
|||
|
||||
// Extracting extra headers from RequestHeadType. HeaderMap::new() does not allocate.
|
||||
let (head, extra_headers) = match head {
|
||||
RequestHeadType::Owned(head) => (RequestHeadType::Owned(head), HeaderMap::new()),
|
||||
RequestHeadType::Rc(head, extra_headers) => (RequestHeadType::Rc(head, None), extra_headers.unwrap_or(HeaderMap::new())),
|
||||
RequestHeadType::Owned(head) => {
|
||||
(RequestHeadType::Owned(head), HeaderMap::new())
|
||||
}
|
||||
RequestHeadType::Rc(head, extra_headers) => (
|
||||
RequestHeadType::Rc(head, None),
|
||||
extra_headers.unwrap_or_else(HeaderMap::new),
|
||||
),
|
||||
};
|
||||
|
||||
// merging headers from head and extra headers.
|
||||
let headers = head.as_ref().headers.iter()
|
||||
.filter(|(name, _)| {
|
||||
!extra_headers.contains_key(*name)
|
||||
})
|
||||
let headers = head
|
||||
.as_ref()
|
||||
.headers
|
||||
.iter()
|
||||
.filter(|(name, _)| !extra_headers.contains_key(*name))
|
||||
.chain(extra_headers.iter());
|
||||
|
||||
// copy headers
|
||||
|
|
|
@ -10,7 +10,7 @@ mod pool;
|
|||
|
||||
pub use self::connection::Connection;
|
||||
pub use self::connector::Connector;
|
||||
pub use self::error::{ConnectError, InvalidUrl, SendRequestError, FreezeRequestError};
|
||||
pub use self::error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
|
||||
pub use self::pool::Protocol;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -326,7 +326,7 @@ impl<Io> Inner<Io> {
|
|||
|
||||
fn release_waiter(&mut self, key: &Key, token: usize) {
|
||||
self.waiters.remove(token);
|
||||
self.waiters_queue.remove(&(key.clone(), token));
|
||||
let _ = self.waiters_queue.shift_remove(&(key.clone(), token));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,11 @@ use super::{Message, MessageType};
|
|||
use crate::body::BodySize;
|
||||
use crate::config::ServiceConfig;
|
||||
use crate::error::{ParseError, PayloadError};
|
||||
use crate::helpers;
|
||||
use crate::message::{ConnectionType, Head, MessagePool, RequestHead, RequestHeadType, ResponseHead};
|
||||
use crate::header::HeaderMap;
|
||||
use crate::helpers;
|
||||
use crate::message::{
|
||||
ConnectionType, Head, MessagePool, RequestHead, RequestHeadType, ResponseHead,
|
||||
};
|
||||
|
||||
bitflags! {
|
||||
struct Flags: u8 {
|
||||
|
@ -197,7 +199,9 @@ impl Encoder for ClientCodec {
|
|||
Message::Item((mut head, length)) => {
|
||||
let inner = &mut self.inner;
|
||||
inner.version = head.as_ref().version;
|
||||
inner.flags.set(Flags::HEAD, head.as_ref().method == Method::HEAD);
|
||||
inner
|
||||
.flags
|
||||
.set(Flags::HEAD, head.as_ref().method == Method::HEAD);
|
||||
|
||||
// connection status
|
||||
inner.ctype = match head.as_ref().connection_type() {
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
use std::fmt::Write as FmtWrite;
|
||||
use std::io::Write;
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use std::{cmp, fmt, io, mem};
|
||||
use std::rc::Rc;
|
||||
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
|
||||
|
@ -16,7 +16,7 @@ use crate::http::header::{
|
|||
HeaderValue, ACCEPT_ENCODING, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING,
|
||||
};
|
||||
use crate::http::{HeaderMap, Method, StatusCode, Version};
|
||||
use crate::message::{ConnectionType, Head, RequestHead, ResponseHead, RequestHeadType};
|
||||
use crate::message::{ConnectionType, Head, RequestHead, RequestHeadType, ResponseHead};
|
||||
use crate::request::Request;
|
||||
use crate::response::Response;
|
||||
|
||||
|
@ -134,10 +134,11 @@ pub(crate) trait MessageType: Sized {
|
|||
// merging headers from head and extra headers. HeaderMap::new() does not allocate.
|
||||
let empty_headers = HeaderMap::new();
|
||||
let extra_headers = self.extra_headers().unwrap_or(&empty_headers);
|
||||
let headers = self.headers().inner.iter()
|
||||
.filter(|(name, _)| {
|
||||
!extra_headers.contains_key(*name)
|
||||
})
|
||||
let headers = self
|
||||
.headers()
|
||||
.inner
|
||||
.iter()
|
||||
.filter(|(name, _)| !extra_headers.contains_key(*name))
|
||||
.chain(extra_headers.inner.iter());
|
||||
|
||||
// write headers
|
||||
|
@ -604,10 +605,16 @@ mod tests {
|
|||
let mut bytes = BytesMut::with_capacity(2048);
|
||||
|
||||
let mut head = RequestHead::default();
|
||||
head.headers.insert(AUTHORIZATION, HeaderValue::from_static("some authorization"));
|
||||
head.headers.insert(
|
||||
AUTHORIZATION,
|
||||
HeaderValue::from_static("some authorization"),
|
||||
);
|
||||
|
||||
let mut extra_headers = HeaderMap::new();
|
||||
extra_headers.insert(AUTHORIZATION,HeaderValue::from_static("another authorization"));
|
||||
extra_headers.insert(
|
||||
AUTHORIZATION,
|
||||
HeaderValue::from_static("another authorization"),
|
||||
);
|
||||
extra_headers.insert(DATE, HeaderValue::from_static("date"));
|
||||
|
||||
let mut head = RequestHeadType::Rc(Rc::new(head), Some(extra_headers));
|
||||
|
|
|
@ -178,13 +178,15 @@ impl InnerMultipart {
|
|||
Some(chunk) => {
|
||||
if chunk.len() < boundary.len() + 4
|
||||
|| &chunk[..2] != b"--"
|
||||
|| &chunk[2..boundary.len() + 2] != boundary.as_bytes() {
|
||||
|| &chunk[2..boundary.len() + 2] != boundary.as_bytes()
|
||||
{
|
||||
Err(MultipartError::Boundary)
|
||||
} else if &chunk[boundary.len() + 2..] == b"\r\n" {
|
||||
Ok(Some(false))
|
||||
} else if &chunk[boundary.len() + 2..boundary.len() + 4] == b"--"
|
||||
&& (chunk.len() == boundary.len() + 4
|
||||
|| &chunk[boundary.len() + 4..] == b"\r\n") {
|
||||
|| &chunk[boundary.len() + 4..] == b"\r\n")
|
||||
{
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
Err(MultipartError::Boundary)
|
||||
|
@ -781,8 +783,10 @@ impl PayloadBuffer {
|
|||
/// Read bytes until new line delimiter or eof
|
||||
pub fn readline_or_eof(&mut self) -> Result<Option<Bytes>, MultipartError> {
|
||||
match self.readline() {
|
||||
Err(MultipartError::Incomplete) if self.eof => Ok(Some(self.buf.take().freeze())),
|
||||
line => line
|
||||
Err(MultipartError::Incomplete) if self.eof => {
|
||||
Ok(Some(self.buf.take().freeze()))
|
||||
}
|
||||
line => line,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -859,14 +863,14 @@ mod tests {
|
|||
fn create_simple_request_with_header() -> (Bytes, HeaderMap) {
|
||||
let bytes = Bytes::from(
|
||||
"testasdadsad\r\n\
|
||||
--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
|
||||
Content-Disposition: form-data; name=\"file\"; filename=\"fn.txt\"\r\n\
|
||||
Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\
|
||||
test\r\n\
|
||||
--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
|
||||
Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\
|
||||
data\r\n\
|
||||
--abbc761f78ff4d7cb7573b5a23f96ef0--\r\n"
|
||||
--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
|
||||
Content-Disposition: form-data; name=\"file\"; filename=\"fn.txt\"\r\n\
|
||||
Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\
|
||||
test\r\n\
|
||||
--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
|
||||
Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\
|
||||
data\r\n\
|
||||
--abbc761f78ff4d7cb7573b5a23f96ef0--\r\n",
|
||||
);
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::{fmt, io, net};
|
||||
use std::rc::Rc;
|
||||
use std::{fmt, io, net};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_http::body::Body;
|
||||
|
@ -7,8 +7,8 @@ use actix_http::client::{
|
|||
Connect as ClientConnect, ConnectError, Connection, SendRequestError,
|
||||
};
|
||||
use actix_http::h1::ClientCodec;
|
||||
use actix_http::{RequestHead, RequestHeadType, ResponseHead};
|
||||
use actix_http::http::HeaderMap;
|
||||
use actix_http::{RequestHead, RequestHeadType, ResponseHead};
|
||||
use actix_service::Service;
|
||||
use futures::{Future, Poll};
|
||||
|
||||
|
@ -82,7 +82,9 @@ where
|
|||
})
|
||||
.from_err()
|
||||
// send request
|
||||
.and_then(move |connection| connection.send_request(RequestHeadType::from(head), body))
|
||||
.and_then(move |connection| {
|
||||
connection.send_request(RequestHeadType::from(head), body)
|
||||
})
|
||||
.map(|(head, payload)| ClientResponse::new(head, payload)),
|
||||
)
|
||||
}
|
||||
|
@ -103,7 +105,10 @@ where
|
|||
})
|
||||
.from_err()
|
||||
// send request
|
||||
.and_then(move |connection| connection.send_request(RequestHeadType::Rc(head, extra_headers), body))
|
||||
.and_then(move |connection| {
|
||||
connection
|
||||
.send_request(RequestHeadType::Rc(head, extra_headers), body)
|
||||
})
|
||||
.map(|(head, payload)| ClientResponse::new(head, payload)),
|
||||
)
|
||||
}
|
||||
|
@ -127,7 +132,9 @@ where
|
|||
})
|
||||
.from_err()
|
||||
// send request
|
||||
.and_then(move |connection| connection.open_tunnel(RequestHeadType::from(head)))
|
||||
.and_then(move |connection| {
|
||||
connection.open_tunnel(RequestHeadType::from(head))
|
||||
})
|
||||
.map(|(head, framed)| {
|
||||
let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
||||
(head, framed)
|
||||
|
@ -155,7 +162,9 @@ where
|
|||
})
|
||||
.from_err()
|
||||
// send request
|
||||
.and_then(move |connection| connection.open_tunnel(RequestHeadType::Rc(head, extra_headers)))
|
||||
.and_then(move |connection| {
|
||||
connection.open_tunnel(RequestHeadType::Rc(head, extra_headers))
|
||||
})
|
||||
.map(|(head, framed)| {
|
||||
let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
||||
(head, framed)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! Http client errors
|
||||
pub use actix_http::client::{ConnectError, InvalidUrl, SendRequestError, FreezeRequestError};
|
||||
pub use actix_http::client::{
|
||||
ConnectError, FreezeRequestError, InvalidUrl, SendRequestError,
|
||||
};
|
||||
pub use actix_http::error::PayloadError;
|
||||
pub use actix_http::ws::HandshakeError as WsHandshakeError;
|
||||
pub use actix_http::ws::ProtocolError as WsProtocolError;
|
||||
|
|
|
@ -90,7 +90,7 @@ impl Future for SendClientRequest {
|
|||
Ok(Async::Ready(res))
|
||||
}
|
||||
SendClientRequest::Err(ref mut e) => match e.take() {
|
||||
Some(e) => Err(e.into()),
|
||||
Some(e) => Err(e),
|
||||
None => panic!("Attempting to call completed future"),
|
||||
},
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ impl RequestSender {
|
|||
SendClientRequest::new(
|
||||
fut,
|
||||
response_decompress,
|
||||
timeout.or_else(|| config.timeout.clone()),
|
||||
timeout.or_else(|| config.timeout),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,10 @@ impl WebsocketsRequest {
|
|||
}
|
||||
|
||||
if !self.head.headers.contains_key(header::HOST) {
|
||||
self.head.headers.insert(header::HOST, HeaderValue::from_str(uri.host().unwrap()).unwrap());
|
||||
self.head.headers.insert(
|
||||
header::HOST,
|
||||
HeaderValue::from_str(uri.host().unwrap()).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
// set cookies
|
||||
|
|
|
@ -169,7 +169,7 @@ where
|
|||
match self.data_factories_fut[idx].poll()? {
|
||||
Async::Ready(f) => {
|
||||
self.data_factories.push(f);
|
||||
self.data_factories_fut.remove(idx);
|
||||
let _ = self.data_factories_fut.remove(idx);
|
||||
}
|
||||
Async::NotReady => idx += 1,
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
mod compress;
|
||||
pub use self::compress::{BodyEncoding, Compress};
|
||||
|
||||
mod condition;
|
||||
mod defaultheaders;
|
||||
pub mod errhandlers;
|
||||
mod logger;
|
||||
mod normalize;
|
||||
mod condition;
|
||||
|
||||
pub use self::condition::Condition;
|
||||
pub use self::defaultheaders::DefaultHeaders;
|
||||
pub use self::logger::Logger;
|
||||
pub use self::normalize::NormalizePath;
|
||||
pub use self::condition::Condition;
|
||||
|
|
Loading…
Reference in a new issue