mirror of https://github.com/fafhrd91/actix-web
fix camel case head test
This commit is contained in:
parent
f0faadad09
commit
42c29e47cb
|
@ -39,7 +39,7 @@ where
|
|||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
HttpServiceBuilder {
|
||||
keep_alive: KeepAlive::Timeout(5),
|
||||
keep_alive: KeepAlive::default(),
|
||||
client_timeout: 5000,
|
||||
client_disconnect: 0,
|
||||
secure: false,
|
||||
|
|
|
@ -18,8 +18,8 @@ pub(crate) const DATE_VALUE_LENGTH: usize = 29;
|
|||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
/// Server keep-alive setting
|
||||
pub enum KeepAlive {
|
||||
/// Keep-alive time in seconds.
|
||||
Timeout(usize),
|
||||
/// Keep-alive duration.
|
||||
Timeout(Duration),
|
||||
|
||||
/// Rely on OS to shutdown TCP connection.
|
||||
Os,
|
||||
|
@ -28,18 +28,23 @@ pub enum KeepAlive {
|
|||
Disabled,
|
||||
}
|
||||
|
||||
impl Default for KeepAlive {
|
||||
fn default() -> Self {
|
||||
Self::Timeout(Duration::from_secs(5))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for KeepAlive {
|
||||
fn from(keepalive: usize) -> Self {
|
||||
KeepAlive::Timeout(keepalive)
|
||||
fn from(ka_secs: usize) -> Self {
|
||||
KeepAlive::Timeout(Duration::from_secs(ka_secs as u64))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<usize>> for KeepAlive {
|
||||
fn from(keepalive: Option<usize>) -> Self {
|
||||
if let Some(keepalive) = keepalive {
|
||||
KeepAlive::Timeout(keepalive)
|
||||
} else {
|
||||
KeepAlive::Disabled
|
||||
fn from(ka_secs_opt: Option<usize>) -> Self {
|
||||
match ka_secs_opt {
|
||||
Some(ka_secs) => KeepAlive::Timeout(Duration::from_secs(ka_secs as u64)),
|
||||
None => KeepAlive::Disabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +66,7 @@ struct Inner {
|
|||
|
||||
impl Default for ServiceConfig {
|
||||
fn default() -> Self {
|
||||
Self::new(KeepAlive::Timeout(5), 0, 0, false, None)
|
||||
Self::new(KeepAlive::default(), 0, 0, false, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +80,13 @@ impl ServiceConfig {
|
|||
local_addr: Option<net::SocketAddr>,
|
||||
) -> ServiceConfig {
|
||||
let (keep_alive, ka_enabled) = match keep_alive {
|
||||
KeepAlive::Timeout(val) => (val as u64, true),
|
||||
KeepAlive::Os => (0, true),
|
||||
KeepAlive::Disabled => (0, false),
|
||||
KeepAlive::Timeout(Duration::ZERO) => (Duration::ZERO, false),
|
||||
KeepAlive::Timeout(val) => (val, true),
|
||||
KeepAlive::Os => (Duration::ZERO, true),
|
||||
KeepAlive::Disabled => (Duration::ZERO, false),
|
||||
};
|
||||
|
||||
let keep_alive =
|
||||
(ka_enabled && keep_alive > 0).then(|| Duration::from_secs(keep_alive));
|
||||
let keep_alive = ka_enabled.then(|| keep_alive);
|
||||
|
||||
ServiceConfig(Rc::new(Inner {
|
||||
keep_alive,
|
||||
|
|
|
@ -1181,7 +1181,7 @@ where
|
|||
|
||||
#[inline]
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
log::trace!(target: "", "");
|
||||
log::trace!(target: "actix*", "");
|
||||
log::trace!("enter Dispatcher::poll");
|
||||
|
||||
let this = self.as_mut().project();
|
||||
|
|
|
@ -188,7 +188,13 @@ async fn oneshot_connection() {
|
|||
async fn keep_alive_timeout() {
|
||||
let buf = TestBuffer::new("GET /abcd HTTP/1.1\r\n\r\n");
|
||||
|
||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(1), 100, 0, false, None);
|
||||
let cfg = ServiceConfig::new(
|
||||
KeepAlive::Timeout(Duration::from_millis(200)),
|
||||
100,
|
||||
0,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
let services = HttpFlow::new(echo_path_service(), ExpectHandler, None);
|
||||
|
||||
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new(
|
||||
|
@ -235,7 +241,7 @@ async fn keep_alive_timeout() {
|
|||
.await;
|
||||
|
||||
// sleep slightly longer than keep-alive timeout
|
||||
sleep(Duration::from_millis(1100)).await;
|
||||
sleep(Duration::from_millis(250)).await;
|
||||
|
||||
lazy(|cx| {
|
||||
assert!(
|
||||
|
@ -261,7 +267,13 @@ async fn keep_alive_timeout() {
|
|||
async fn keep_alive_follow_up_req() {
|
||||
let mut buf = TestBuffer::new("GET /abcd HTTP/1.1\r\n\r\n");
|
||||
|
||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(2), 100, 0, false, None);
|
||||
let cfg = ServiceConfig::new(
|
||||
KeepAlive::Timeout(Duration::from_millis(500)),
|
||||
100,
|
||||
0,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
let services = HttpFlow::new(echo_path_service(), ExpectHandler, None);
|
||||
|
||||
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new(
|
||||
|
@ -308,7 +320,7 @@ async fn keep_alive_follow_up_req() {
|
|||
.await;
|
||||
|
||||
// sleep for less than KA timeout
|
||||
sleep(Duration::from_millis(200)).await;
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
|
||||
lazy(|cx| {
|
||||
assert!(
|
||||
|
|
|
@ -208,7 +208,6 @@ mod tests {
|
|||
};
|
||||
|
||||
use memchr::memmem;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest};
|
||||
|
||||
use crate::{
|
||||
h1::H1Service,
|
||||
|
@ -239,14 +238,12 @@ mod tests {
|
|||
})
|
||||
.await;
|
||||
|
||||
let mut stream = tokio::net::TcpStream::connect(srv.addr()).await.unwrap();
|
||||
dbg!(stream.ready(Interest::WRITABLE).await.unwrap());
|
||||
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
|
||||
let _ = stream
|
||||
.write_all(b"GET /camel HTTP/1.1\r\nConnection: Close\r\n\r\n")
|
||||
.await
|
||||
.unwrap();
|
||||
let mut data = vec![0; 1024];
|
||||
let _ = stream.read_to_end(&mut data).await.unwrap();
|
||||
let mut data = vec![0; 256];
|
||||
let _ = stream.read(&mut data).unwrap();
|
||||
assert_eq!(&data[..17], b"HTTP/1.1 200 OK\r\n");
|
||||
assert!(memmem::find(&data, b"Foo-Bar").is_some());
|
||||
assert!(memmem::find(&data, b"foo-bar").is_none());
|
||||
|
@ -259,8 +256,8 @@ mod tests {
|
|||
let _ = stream
|
||||
.write_all(b"GET /lower HTTP/1.1\r\nConnection: Close\r\n\r\n")
|
||||
.unwrap();
|
||||
let mut data = vec![0; 1024];
|
||||
let _ = stream.read_to_end(&mut data).unwrap();
|
||||
let mut data = vec![0; 256];
|
||||
let _ = stream.read(&mut data).unwrap();
|
||||
assert_eq!(&data[..17], b"HTTP/1.1 200 OK\r\n");
|
||||
assert!(memmem::find(&data, b"Foo-Bar").is_none());
|
||||
assert!(memmem::find(&data, b"foo-bar").is_some());
|
||||
|
|
|
@ -60,7 +60,7 @@ where
|
|||
{
|
||||
/// Create new `HttpService` instance.
|
||||
pub fn new<F: IntoServiceFactory<S, Request>>(service: F) -> Self {
|
||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0, false, None);
|
||||
let cfg = ServiceConfig::new(KeepAlive::default(), 5000, 0, false, None);
|
||||
|
||||
HttpService {
|
||||
cfg,
|
||||
|
|
|
@ -88,7 +88,7 @@ where
|
|||
factory,
|
||||
config: Arc::new(Mutex::new(Config {
|
||||
host: None,
|
||||
keep_alive: KeepAlive::Timeout(5),
|
||||
keep_alive: KeepAlive::default(),
|
||||
client_timeout: 5000,
|
||||
client_shutdown: 5000,
|
||||
})),
|
||||
|
|
Loading…
Reference in New Issue