@@ -152,26 +157,28 @@ where
});
}
Poll::Ready(None) => return Poll::Ready(Ok(())),
+
Poll::Pending => match this.ping_pong.as_mut() {
Some(ping_pong) => loop {
- if ping_pong.on_flight {
- // When have on flight ping pong. poll pong and and keep alive timer.
- // on success pong received update keep alive timer to determine the next timing of
- // ping pong.
+ if ping_pong.in_flight {
+ // When there is an in-flight ping-pong, poll pong and and keep-alive
+ // timer. On successful pong received, update keep-alive timer to
+ // determine the next timing of ping pong.
match ping_pong.ping_pong.poll_pong(cx)? {
Poll::Ready(_) => {
- ping_pong.on_flight = false;
+ ping_pong.in_flight = false;
let dead_line = this.config.keep_alive_deadline().unwrap();
ping_pong.timer.as_mut().reset(dead_line.into());
}
Poll::Pending => {
- return ping_pong.timer.as_mut().poll(cx).map(|_| Ok(()))
+ return ping_pong.timer.as_mut().poll(cx).map(|_| Ok(()));
}
}
} else {
- // When there is no on flight ping pong. keep alive timer is used to wait for next
- // timing of ping pong. Therefore at this point it serves as an interval instead.
+ // When there is no in-flight ping-pong, keep-alive timer is used to
+ // wait for next timing of ping-pong. Therefore, at this point it serves
+ // as an interval instead.
ready!(ping_pong.timer.as_mut().poll(cx));
ping_pong.ping_pong.send_ping(Ping::opaque())?;
@@ -179,7 +186,7 @@ where
let dead_line = this.config.keep_alive_deadline().unwrap();
ping_pong.timer.as_mut().reset(dead_line.into());
- ping_pong.on_flight = true;
+ ping_pong.in_flight = true;
}
},
None => return Poll::Pending,
@@ -287,13 +294,13 @@ fn prepare_response(
_ => {}
}
- let _ = match size {
- BodySize::None | BodySize::Stream => None,
+ match size {
+ BodySize::None | BodySize::Stream => {}
BodySize::Sized(0) => {
#[allow(clippy::declare_interior_mutable_const)]
const HV_ZERO: HeaderValue = HeaderValue::from_static("0");
- res.headers_mut().insert(CONTENT_LENGTH, HV_ZERO)
+ res.headers_mut().insert(CONTENT_LENGTH, HV_ZERO);
}
BodySize::Sized(len) => {
@@ -302,7 +309,7 @@ fn prepare_response(
res.headers_mut().insert(
CONTENT_LENGTH,
HeaderValue::from_str(buf.format(*len)).unwrap(),
- )
+ );
}
};
diff --git a/actix-http/src/h2/mod.rs b/actix-http/src/h2/mod.rs
index c8aaaaa5f..39198e0fe 100644
--- a/actix-http/src/h2/mod.rs
+++ b/actix-http/src/h2/mod.rs
@@ -103,11 +103,9 @@ where
#[cfg(test)]
mod tests {
- use std::panic::{RefUnwindSafe, UnwindSafe};
-
use static_assertions::assert_impl_all;
use super::*;
- assert_impl_all!(Payload: Unpin, Send, Sync, UnwindSafe, RefUnwindSafe);
+ assert_impl_all!(Payload: Unpin, Send, Sync);
}
diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs
index e526918c7..2a45fc1dc 100644
--- a/actix-http/src/h2/service.rs
+++ b/actix-http/src/h2/service.rs
@@ -117,6 +117,7 @@ mod openssl {
B: MessageBody + 'static,
{
/// Create OpenSSL based service.
+ #[cfg_attr(docsrs, doc(cfg(feature = "openssl")))]
pub fn openssl(
self,
acceptor: SslAcceptor,
@@ -164,6 +165,7 @@ mod rustls {
B: MessageBody + 'static,
{
/// Create Rustls based service.
+ #[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
pub fn rustls(
self,
mut config: ServerConfig,
diff --git a/actix-http/src/header/map.rs b/actix-http/src/header/map.rs
index 8f6d1cead..28906e835 100644
--- a/actix-http/src/header/map.rs
+++ b/actix-http/src/header/map.rs
@@ -309,7 +309,7 @@ impl HeaderMap {
pub fn get_all(&self, key: impl AsHeaderName) -> std::slice::Iter<'_, HeaderValue> {
match self.get_value(key) {
Some(value) => value.iter(),
- None => (&[]).iter(),
+ None => [].iter(),
}
}
diff --git a/actix-http/src/header/shared/extended.rs b/actix-http/src/header/shared/extended.rs
index 1af9ca20e..cd8adb2bd 100644
--- a/actix-http/src/header/shared/extended.rs
+++ b/actix-http/src/header/shared/extended.rs
@@ -12,7 +12,7 @@ use crate::header::{Charset, HTTP_VALUE};
/// - A character sequence representing the actual value (`value`), separated by single quotes.
///
/// It is defined in [RFC 5987 §3.2](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2).
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExtendedValue {
/// The character set that is used to encode the `value` to a string.
pub charset: Charset,
diff --git a/actix-http/src/header/shared/quality_item.rs b/actix-http/src/header/shared/quality_item.rs
index 71a3bdd53..0b35b5401 100644
--- a/actix-http/src/header/shared/quality_item.rs
+++ b/actix-http/src/header/shared/quality_item.rs
@@ -147,7 +147,7 @@ mod tests {
// copy of encoding from actix-web headers
#[allow(clippy::enum_variant_names)] // allow Encoding prefix on EncodingExt
- #[derive(Clone, PartialEq, Debug)]
+ #[derive(Debug, Clone, PartialEq, Eq)]
pub enum Encoding {
Chunked,
Brotli,
diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs
index 360cb86fc..864db4986 100644
--- a/actix-http/src/lib.rs
+++ b/actix-http/src/lib.rs
@@ -25,6 +25,7 @@
)]
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
+#![cfg_attr(docsrs, feature(doc_cfg))]
pub use ::http::{uri, uri::Uri};
pub use ::http::{Method, StatusCode, Version};
@@ -39,6 +40,7 @@ pub mod error;
mod extensions;
pub mod h1;
#[cfg(feature = "http2")]
+#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub mod h2;
pub mod header;
mod helpers;
@@ -53,6 +55,7 @@ mod responses;
mod service;
pub mod test;
#[cfg(feature = "ws")]
+#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
pub mod ws;
pub use self::builder::HttpServiceBuilder;
@@ -69,6 +72,9 @@ pub use self::payload::{BoxedPayloadStream, Payload, PayloadStream};
pub use self::requests::{Request, RequestHead, RequestHeadType};
pub use self::responses::{Response, ResponseBuilder, ResponseHead};
pub use self::service::HttpService;
+#[cfg(any(feature = "openssl", feature = "rustls"))]
+#[cfg_attr(docsrs, doc(cfg(any(feature = "openssl", feature = "rustls"))))]
+pub use self::service::TlsAcceptorConfig;
/// A major HTTP protocol version.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs
index 5616a4762..7469d74ee 100644
--- a/actix-http/src/message.rs
+++ b/actix-http/src/message.rs
@@ -3,7 +3,7 @@ use std::{cell::RefCell, ops, rc::Rc};
use bitflags::bitflags;
/// Represents various types of connection
-#[derive(Copy, Clone, PartialEq, Debug)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionType {
/// Close connection after response.
Close,
diff --git a/actix-http/src/payload.rs b/actix-http/src/payload.rs
index ee0128af4..7d476c55f 100644
--- a/actix-http/src/payload.rs
+++ b/actix-http/src/payload.rs
@@ -97,12 +97,10 @@ where
#[cfg(test)]
mod tests {
- use std::panic::{RefUnwindSafe, UnwindSafe};
-
use static_assertions::{assert_impl_all, assert_not_impl_any};
use super::*;
assert_impl_all!(Payload: Unpin);
- assert_not_impl_any!(Payload: Send, Sync, UnwindSafe, RefUnwindSafe);
+ assert_not_impl_any!(Payload: Send, Sync);
}
diff --git a/actix-http/src/requests/request.rs b/actix-http/src/requests/request.rs
index 0f8e78d46..ac358e8df 100644
--- a/actix-http/src/requests/request.rs
+++ b/actix-http/src/requests/request.rs
@@ -113,14 +113,14 @@ impl Request
{
#[inline]
/// Http message part of the request
pub fn head(&self) -> &RequestHead {
- &*self.head
+ &self.head
}
#[inline]
#[doc(hidden)]
/// Mutable reference to a HTTP message part of the request
pub fn head_mut(&mut self) -> &mut RequestHead {
- &mut *self.head
+ &mut self.head
}
/// Mutable reference to the message's headers.
diff --git a/actix-http/src/responses/head.rs b/actix-http/src/responses/head.rs
index cb47c4b7a..01bca6c5b 100644
--- a/actix-http/src/responses/head.rs
+++ b/actix-http/src/responses/head.rs
@@ -237,7 +237,7 @@ mod tests {
.await;
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
- let _ = stream
+ stream
.write_all(b"GET /camel HTTP/1.1\r\nConnection: Close\r\n\r\n")
.unwrap();
let mut data = vec![];
@@ -251,7 +251,7 @@ mod tests {
assert!(memmem::find(&data, b"content-length").is_none());
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
- let _ = stream
+ stream
.write_all(b"GET /lower HTTP/1.1\r\nConnection: Close\r\n\r\n")
.unwrap();
let mut data = vec![];
diff --git a/actix-http/src/responses/response.rs b/actix-http/src/responses/response.rs
index ceb158f65..03908d9ce 100644
--- a/actix-http/src/responses/response.rs
+++ b/actix-http/src/responses/response.rs
@@ -83,13 +83,13 @@ impl Response {
/// Returns a reference to the head of this response.
#[inline]
pub fn head(&self) -> &ResponseHead {
- &*self.head
+ &self.head
}
/// Returns a mutable reference to the head of this response.
#[inline]
pub fn head_mut(&mut self) -> &mut ResponseHead {
- &mut *self.head
+ &mut self.head
}
/// Returns the status code of this response.
diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs
index f4fe625a3..bcca5b188 100644
--- a/actix-http/src/service.rs
+++ b/actix-http/src/service.rs
@@ -181,6 +181,25 @@ where
}
}
+/// Configuration options used when accepting TLS connection.
+#[cfg(any(feature = "openssl", feature = "rustls"))]
+#[cfg_attr(docsrs, doc(cfg(any(feature = "openssl", feature = "rustls"))))]
+#[derive(Debug, Default)]
+pub struct TlsAcceptorConfig {
+ pub(crate) handshake_timeout: Option,
+}
+
+#[cfg(any(feature = "openssl", feature = "rustls"))]
+impl TlsAcceptorConfig {
+ /// Set TLS handshake timeout duration.
+ pub fn handshake_timeout(self, dur: std::time::Duration) -> Self {
+ Self {
+ handshake_timeout: Some(dur),
+ // ..self
+ }
+ }
+}
+
#[cfg(feature = "openssl")]
mod openssl {
use actix_service::ServiceFactoryExt as _;
@@ -220,6 +239,7 @@ mod openssl {
U::InitError: fmt::Debug,
{
/// Create OpenSSL based service.
+ #[cfg_attr(docsrs, doc(cfg(feature = "openssl")))]
pub fn openssl(
self,
acceptor: SslAcceptor,
@@ -230,7 +250,29 @@ mod openssl {
Error = TlsError,
InitError = (),
> {
- Acceptor::new(acceptor)
+ self.openssl_with_config(acceptor, TlsAcceptorConfig::default())
+ }
+
+ /// Create OpenSSL based service with custom TLS acceptor configuration.
+ #[cfg_attr(docsrs, doc(cfg(feature = "openssl")))]
+ pub fn openssl_with_config(
+ self,
+ acceptor: SslAcceptor,
+ tls_acceptor_config: TlsAcceptorConfig,
+ ) -> impl ServiceFactory<
+ TcpStream,
+ Config = (),
+ Response = (),
+ Error = TlsError,
+ InitError = (),
+ > {
+ let mut acceptor = Acceptor::new(acceptor);
+
+ if let Some(handshake_timeout) = tls_acceptor_config.handshake_timeout {
+ acceptor.set_handshake_timeout(handshake_timeout);
+ }
+
+ acceptor
.map_init_err(|_| {
unreachable!("TLS acceptor service factory does not error on init")
})
@@ -292,9 +334,26 @@ mod rustls {
U::InitError: fmt::Debug,
{
/// Create Rustls based service.
+ #[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
pub fn rustls(
+ self,
+ config: ServerConfig,
+ ) -> impl ServiceFactory<
+ TcpStream,
+ Config = (),
+ Response = (),
+ Error = TlsError,
+ InitError = (),
+ > {
+ self.rustls_with_config(config, TlsAcceptorConfig::default())
+ }
+
+ /// Create Rustls based service with custom TLS acceptor configuration.
+ #[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
+ pub fn rustls_with_config(
self,
mut config: ServerConfig,
+ tls_acceptor_config: TlsAcceptorConfig,
) -> impl ServiceFactory<
TcpStream,
Config = (),
@@ -306,7 +365,13 @@ mod rustls {
protos.extend_from_slice(&config.alpn_protocols);
config.alpn_protocols = protos;
- Acceptor::new(config)
+ let mut acceptor = Acceptor::new(config);
+
+ if let Some(handshake_timeout) = tls_acceptor_config.handshake_timeout {
+ acceptor.set_handshake_timeout(handshake_timeout);
+ }
+
+ acceptor
.map_init_err(|_| {
unreachable!("TLS acceptor service factory does not error on init")
})
diff --git a/actix-http/src/test.rs b/actix-http/src/test.rs
index 6212c19d1..3815e64c6 100644
--- a/actix-http/src/test.rs
+++ b/actix-http/src/test.rs
@@ -19,29 +19,7 @@ use crate::{
Request,
};
-/// Test `Request` builder
-///
-/// ```ignore
-/// # use http::{header, StatusCode};
-/// # use actix_web::*;
-/// use actix_web::test::TestRequest;
-///
-/// fn index(req: &HttpRequest) -> Response {
-/// if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) {
-/// Response::Ok().into()
-/// } else {
-/// Response::BadRequest().into()
-/// }
-/// }
-///
-/// let resp = TestRequest::default().insert_header("content-type", "text/plain")
-/// .run(&index)
-/// .unwrap();
-/// assert_eq!(resp.status(), StatusCode::OK);
-///
-/// let resp = TestRequest::default().run(&index).unwrap();
-/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
-/// ```
+/// Test `Request` builder.
pub struct TestRequest(Option);
struct Inner {
diff --git a/actix-http/src/ws/codec.rs b/actix-http/src/ws/codec.rs
index 3aa325d6a..4a2e741b6 100644
--- a/actix-http/src/ws/codec.rs
+++ b/actix-http/src/ws/codec.rs
@@ -11,7 +11,7 @@ use super::{
};
/// A WebSocket message.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Message {
/// Text message.
Text(ByteString),
@@ -36,7 +36,7 @@ pub enum Message {
}
/// A WebSocket frame.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Frame {
/// Text frame. Note that the codec does not validate UTF-8 encoding.
Text(Bytes),
@@ -58,7 +58,7 @@ pub enum Frame {
}
/// A WebSocket continuation item.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Item {
FirstText(Bytes),
FirstBinary(Bytes),
diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs
index 17e34e2ba..c7e0427ea 100644
--- a/actix-http/src/ws/frame.rs
+++ b/actix-http/src/ws/frame.rs
@@ -17,7 +17,6 @@ impl Parser {
fn parse_metadata(
src: &[u8],
server: bool,
- max_size: usize,
) -> Result