mirror of
https://github.com/actix/actix-web.git
synced 2024-12-24 17:10:33 +00:00
fmt
This commit is contained in:
parent
0b42cae082
commit
a2b170fec9
5 changed files with 71 additions and 70 deletions
|
@ -19,36 +19,28 @@ use tokio_timer::Delay;
|
|||
#[cfg(feature = "alpn")]
|
||||
use {
|
||||
openssl::ssl::{Error as SslError, SslConnector, SslMethod},
|
||||
tokio_openssl::SslConnectorExt
|
||||
tokio_openssl::SslConnectorExt,
|
||||
};
|
||||
|
||||
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
||||
use {
|
||||
native_tls::{Error as SslError, TlsConnector as NativeTlsConnector},
|
||||
tokio_tls::TlsConnector as SslConnector
|
||||
tokio_tls::TlsConnector as SslConnector,
|
||||
};
|
||||
|
||||
#[cfg(
|
||||
all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
)
|
||||
)]
|
||||
#[cfg(all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
))]
|
||||
use {
|
||||
rustls::ClientConfig,
|
||||
std::io::Error as SslError,
|
||||
std::sync::Arc,
|
||||
tokio_rustls::ClientConfigExt,
|
||||
webpki::DNSNameRef,
|
||||
webpki_roots,
|
||||
rustls::ClientConfig, std::io::Error as SslError, std::sync::Arc,
|
||||
tokio_rustls::ClientConfigExt, webpki::DNSNameRef, webpki_roots,
|
||||
};
|
||||
|
||||
#[cfg(
|
||||
all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
)
|
||||
)]
|
||||
#[cfg(all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
))]
|
||||
type SslConnector = Arc<ClientConfig>;
|
||||
|
||||
#[cfg(not(any(feature = "alpn", feature = "tls", feature = "rust-tls")))]
|
||||
|
@ -255,17 +247,19 @@ impl Default for ClientConnector {
|
|||
fn default() -> ClientConnector {
|
||||
let connector = {
|
||||
#[cfg(all(feature = "alpn"))]
|
||||
{ SslConnector::builder(SslMethod::tls()).unwrap().build() }
|
||||
{
|
||||
SslConnector::builder(SslMethod::tls()).unwrap().build()
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
||||
{ NativeTlsConnector::builder().build().unwrap().into() }
|
||||
{
|
||||
NativeTlsConnector::builder().build().unwrap().into()
|
||||
}
|
||||
|
||||
#[cfg(
|
||||
all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
)
|
||||
)]
|
||||
#[cfg(all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
))]
|
||||
{
|
||||
let mut config = ClientConfig::new();
|
||||
config
|
||||
|
@ -275,7 +269,9 @@ impl Default for ClientConnector {
|
|||
}
|
||||
|
||||
#[cfg(not(any(feature = "alpn", feature = "tls", feature = "rust-tls")))]
|
||||
{ () }
|
||||
{
|
||||
()
|
||||
}
|
||||
};
|
||||
|
||||
ClientConnector::with_connector_impl(connector)
|
||||
|
@ -327,12 +323,10 @@ impl ClientConnector {
|
|||
Self::with_connector_impl(connector)
|
||||
}
|
||||
|
||||
#[cfg(
|
||||
all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
)
|
||||
)]
|
||||
#[cfg(all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
))]
|
||||
/// Create `ClientConnector` actor with custom `SslConnector` instance.
|
||||
///
|
||||
/// By default `ClientConnector` uses very a simple SSL configuration.
|
||||
|
@ -382,12 +376,10 @@ impl ClientConnector {
|
|||
Self::with_connector_impl(Arc::new(connector))
|
||||
}
|
||||
|
||||
#[cfg(
|
||||
all(
|
||||
feature = "tls",
|
||||
not(any(feature = "alpn", feature = "rust-tls"))
|
||||
)
|
||||
)]
|
||||
#[cfg(all(
|
||||
feature = "tls",
|
||||
not(any(feature = "alpn", feature = "rust-tls"))
|
||||
))]
|
||||
pub fn with_connector(connector: SslConnector) -> ClientConnector {
|
||||
// keep level of indirection for docstrings matching featureflags
|
||||
Self::with_connector_impl(connector)
|
||||
|
@ -772,12 +764,10 @@ impl ClientConnector {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(
|
||||
all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
)
|
||||
)]
|
||||
#[cfg(all(
|
||||
feature = "rust-tls",
|
||||
not(any(feature = "alpn", feature = "tls"))
|
||||
))]
|
||||
match res {
|
||||
Err(err) => {
|
||||
let _ = waiter.tx.send(Err(err.into()));
|
||||
|
@ -1263,7 +1253,7 @@ impl AsyncWrite for Connection {
|
|||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
use tokio_tls::{TlsStream};
|
||||
use tokio_tls::TlsStream;
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
/// This is temp solution untile actix-net migration
|
||||
|
|
|
@ -50,7 +50,9 @@ impl HttpResponseParser {
|
|||
}
|
||||
Async::NotReady => {
|
||||
if buf.capacity() >= MAX_BUFFER_SIZE {
|
||||
return Err(HttpResponseParserError::Error(ParseError::TooLarge));
|
||||
return Err(HttpResponseParserError::Error(
|
||||
ParseError::TooLarge,
|
||||
));
|
||||
}
|
||||
// Parser needs more data.
|
||||
}
|
||||
|
@ -63,9 +65,7 @@ impl HttpResponseParser {
|
|||
}
|
||||
Ok(Async::Ready(_)) => (),
|
||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||
Err(err) => {
|
||||
return Err(HttpResponseParserError::Error(err.into()))
|
||||
}
|
||||
Err(err) => return Err(HttpResponseParserError::Error(err.into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -236,7 +236,6 @@ macro_rules! FROM_STR {
|
|||
($type:ty) => {
|
||||
impl FromParam for $type {
|
||||
type Err = InternalError<<$type as FromStr>::Err>;
|
||||
|
||||
fn from_param(val: &str) -> Result<Self, Self::Err> {
|
||||
<$type as FromStr>::from_str(val)
|
||||
.map_err(|e| InternalError::new(e, StatusCode::BAD_REQUEST))
|
||||
|
|
|
@ -160,8 +160,9 @@ where
|
|||
if let Some(HttpProtocol::Unknown(settings, addr, io, buf)) = self.proto.take() {
|
||||
match kind {
|
||||
ProtocolKind::Http1 => {
|
||||
self.proto =
|
||||
Some(HttpProtocol::H1(h1::Http1::new(settings, io, addr, buf, is_eof)));
|
||||
self.proto = Some(HttpProtocol::H1(h1::Http1::new(
|
||||
settings, io, addr, buf, is_eof,
|
||||
)));
|
||||
return self.poll();
|
||||
}
|
||||
ProtocolKind::Http2 => {
|
||||
|
|
|
@ -94,7 +94,11 @@ where
|
|||
buf: BytesMut, is_eof: bool,
|
||||
) -> Self {
|
||||
Http1 {
|
||||
flags: if is_eof { Flags::READ_DISCONNECTED } else { Flags::KEEPALIVE },
|
||||
flags: if is_eof {
|
||||
Flags::READ_DISCONNECTED
|
||||
} else {
|
||||
Flags::KEEPALIVE
|
||||
},
|
||||
stream: H1Writer::new(stream, Rc::clone(&settings)),
|
||||
decoder: H1Decoder::new(),
|
||||
payload: None,
|
||||
|
@ -118,8 +122,11 @@ where
|
|||
|
||||
#[inline]
|
||||
fn can_read(&self) -> bool {
|
||||
if self.flags.intersects(Flags::ERROR | Flags::READ_DISCONNECTED) {
|
||||
return false
|
||||
if self
|
||||
.flags
|
||||
.intersects(Flags::ERROR | Flags::READ_DISCONNECTED)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(ref info) = self.payload {
|
||||
|
@ -171,8 +178,9 @@ where
|
|||
// shutdown
|
||||
if self.flags.contains(Flags::SHUTDOWN) {
|
||||
if self.flags.intersects(
|
||||
Flags::ERROR | Flags::READ_DISCONNECTED | Flags::WRITE_DISCONNECTED) {
|
||||
return Ok(Async::Ready(()))
|
||||
Flags::ERROR | Flags::READ_DISCONNECTED | Flags::WRITE_DISCONNECTED,
|
||||
) {
|
||||
return Ok(Async::Ready(()));
|
||||
}
|
||||
match self.stream.poll_completed(true) {
|
||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||
|
@ -240,7 +248,8 @@ where
|
|||
let mut idx = 0;
|
||||
while idx < self.tasks.len() {
|
||||
// only one task can do io operation in http/1
|
||||
if !io && !self.tasks[idx].flags.contains(EntryFlags::EOF)
|
||||
if !io
|
||||
&& !self.tasks[idx].flags.contains(EntryFlags::EOF)
|
||||
&& !self.flags.contains(Flags::WRITE_DISCONNECTED)
|
||||
{
|
||||
// io is corrupted, send buffer
|
||||
|
@ -291,8 +300,9 @@ where
|
|||
} else if !self.tasks[idx].flags.contains(EntryFlags::FINISHED) {
|
||||
match self.tasks[idx].pipe.poll_completed() {
|
||||
Ok(Async::NotReady) => (),
|
||||
Ok(Async::Ready(_)) =>
|
||||
self.tasks[idx].flags.insert(EntryFlags::FINISHED),
|
||||
Ok(Async::Ready(_)) => {
|
||||
self.tasks[idx].flags.insert(EntryFlags::FINISHED)
|
||||
}
|
||||
Err(err) => {
|
||||
self.notify_disconnect();
|
||||
self.tasks[idx].flags.insert(EntryFlags::ERROR);
|
||||
|
@ -319,9 +329,7 @@ where
|
|||
// check stream state
|
||||
if self.flags.contains(Flags::STARTED) {
|
||||
match self.stream.poll_completed(false) {
|
||||
Ok(Async::NotReady) => {
|
||||
return Ok(Async::NotReady)
|
||||
},
|
||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||
Err(err) => {
|
||||
debug!("Error sending data: {}", err);
|
||||
self.notify_disconnect();
|
||||
|
@ -458,11 +466,13 @@ where
|
|||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
if self.flags.contains(Flags::READ_DISCONNECTED) && self.tasks.is_empty() {
|
||||
if self.flags.contains(Flags::READ_DISCONNECTED)
|
||||
&& self.tasks.is_empty()
|
||||
{
|
||||
self.client_disconnect();
|
||||
}
|
||||
break
|
||||
},
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
self.flags.insert(Flags::ERROR);
|
||||
if let Some(mut payload) = self.payload.take() {
|
||||
|
@ -631,7 +641,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_req_parse2() {
|
||||
let buf = Buffer::new("");
|
||||
let readbuf = BytesMut::from(Vec::<u8>::from(&b"GET /test HTTP/1.1\r\n\r\n"[..]));
|
||||
let readbuf =
|
||||
BytesMut::from(Vec::<u8>::from(&b"GET /test HTTP/1.1\r\n\r\n"[..]));
|
||||
let settings = Rc::new(wrk_settings());
|
||||
|
||||
let mut h1 = Http1::new(Rc::clone(&settings), buf, None, readbuf, true);
|
||||
|
|
Loading…
Reference in a new issue