fix camel case head test

This commit is contained in:
Rob Ede 2022-01-29 03:55:29 +00:00
parent f0faadad09
commit 42c29e47cb
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
7 changed files with 45 additions and 31 deletions

View File

@ -39,7 +39,7 @@ where
#[allow(clippy::new_without_default)] #[allow(clippy::new_without_default)]
pub fn new() -> Self { pub fn new() -> Self {
HttpServiceBuilder { HttpServiceBuilder {
keep_alive: KeepAlive::Timeout(5), keep_alive: KeepAlive::default(),
client_timeout: 5000, client_timeout: 5000,
client_disconnect: 0, client_disconnect: 0,
secure: false, secure: false,

View File

@ -18,8 +18,8 @@ pub(crate) const DATE_VALUE_LENGTH: usize = 29;
#[derive(Debug, PartialEq, Clone, Copy)] #[derive(Debug, PartialEq, Clone, Copy)]
/// Server keep-alive setting /// Server keep-alive setting
pub enum KeepAlive { pub enum KeepAlive {
/// Keep-alive time in seconds. /// Keep-alive duration.
Timeout(usize), Timeout(Duration),
/// Rely on OS to shutdown TCP connection. /// Rely on OS to shutdown TCP connection.
Os, Os,
@ -28,18 +28,23 @@ pub enum KeepAlive {
Disabled, Disabled,
} }
impl Default for KeepAlive {
fn default() -> Self {
Self::Timeout(Duration::from_secs(5))
}
}
impl From<usize> for KeepAlive { impl From<usize> for KeepAlive {
fn from(keepalive: usize) -> Self { fn from(ka_secs: usize) -> Self {
KeepAlive::Timeout(keepalive) KeepAlive::Timeout(Duration::from_secs(ka_secs as u64))
} }
} }
impl From<Option<usize>> for KeepAlive { impl From<Option<usize>> for KeepAlive {
fn from(keepalive: Option<usize>) -> Self { fn from(ka_secs_opt: Option<usize>) -> Self {
if let Some(keepalive) = keepalive { match ka_secs_opt {
KeepAlive::Timeout(keepalive) Some(ka_secs) => KeepAlive::Timeout(Duration::from_secs(ka_secs as u64)),
} else { None => KeepAlive::Disabled,
KeepAlive::Disabled
} }
} }
} }
@ -61,7 +66,7 @@ struct Inner {
impl Default for ServiceConfig { impl Default for ServiceConfig {
fn default() -> Self { 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>, local_addr: Option<net::SocketAddr>,
) -> ServiceConfig { ) -> ServiceConfig {
let (keep_alive, ka_enabled) = match keep_alive { let (keep_alive, ka_enabled) = match keep_alive {
KeepAlive::Timeout(val) => (val as u64, true), KeepAlive::Timeout(Duration::ZERO) => (Duration::ZERO, false),
KeepAlive::Os => (0, true), KeepAlive::Timeout(val) => (val, true),
KeepAlive::Disabled => (0, false), KeepAlive::Os => (Duration::ZERO, true),
KeepAlive::Disabled => (Duration::ZERO, false),
}; };
let keep_alive = let keep_alive = ka_enabled.then(|| keep_alive);
(ka_enabled && keep_alive > 0).then(|| Duration::from_secs(keep_alive));
ServiceConfig(Rc::new(Inner { ServiceConfig(Rc::new(Inner {
keep_alive, keep_alive,

View File

@ -1181,7 +1181,7 @@ where
#[inline] #[inline]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 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"); log::trace!("enter Dispatcher::poll");
let this = self.as_mut().project(); let this = self.as_mut().project();

View File

@ -188,7 +188,13 @@ async fn oneshot_connection() {
async fn keep_alive_timeout() { async fn keep_alive_timeout() {
let buf = TestBuffer::new("GET /abcd HTTP/1.1\r\n\r\n"); 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 services = HttpFlow::new(echo_path_service(), ExpectHandler, None);
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new( let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new(
@ -235,7 +241,7 @@ async fn keep_alive_timeout() {
.await; .await;
// sleep slightly longer than keep-alive timeout // sleep slightly longer than keep-alive timeout
sleep(Duration::from_millis(1100)).await; sleep(Duration::from_millis(250)).await;
lazy(|cx| { lazy(|cx| {
assert!( assert!(
@ -261,7 +267,13 @@ async fn keep_alive_timeout() {
async fn keep_alive_follow_up_req() { async fn keep_alive_follow_up_req() {
let mut buf = TestBuffer::new("GET /abcd HTTP/1.1\r\n\r\n"); 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 services = HttpFlow::new(echo_path_service(), ExpectHandler, None);
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new( let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new(
@ -308,7 +320,7 @@ async fn keep_alive_follow_up_req() {
.await; .await;
// sleep for less than KA timeout // sleep for less than KA timeout
sleep(Duration::from_millis(200)).await; sleep(Duration::from_millis(100)).await;
lazy(|cx| { lazy(|cx| {
assert!( assert!(

View File

@ -208,7 +208,6 @@ mod tests {
}; };
use memchr::memmem; use memchr::memmem;
use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest};
use crate::{ use crate::{
h1::H1Service, h1::H1Service,
@ -239,14 +238,12 @@ mod tests {
}) })
.await; .await;
let mut stream = tokio::net::TcpStream::connect(srv.addr()).await.unwrap(); let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
dbg!(stream.ready(Interest::WRITABLE).await.unwrap());
let _ = stream let _ = stream
.write_all(b"GET /camel HTTP/1.1\r\nConnection: Close\r\n\r\n") .write_all(b"GET /camel HTTP/1.1\r\nConnection: Close\r\n\r\n")
.await
.unwrap(); .unwrap();
let mut data = vec![0; 1024]; let mut data = vec![0; 256];
let _ = stream.read_to_end(&mut data).await.unwrap(); let _ = stream.read(&mut data).unwrap();
assert_eq!(&data[..17], b"HTTP/1.1 200 OK\r\n"); 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_some());
assert!(memmem::find(&data, b"foo-bar").is_none()); assert!(memmem::find(&data, b"foo-bar").is_none());
@ -259,8 +256,8 @@ mod tests {
let _ = stream let _ = stream
.write_all(b"GET /lower HTTP/1.1\r\nConnection: Close\r\n\r\n") .write_all(b"GET /lower HTTP/1.1\r\nConnection: Close\r\n\r\n")
.unwrap(); .unwrap();
let mut data = vec![0; 1024]; let mut data = vec![0; 256];
let _ = stream.read_to_end(&mut data).unwrap(); let _ = stream.read(&mut data).unwrap();
assert_eq!(&data[..17], b"HTTP/1.1 200 OK\r\n"); 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_none());
assert!(memmem::find(&data, b"foo-bar").is_some()); assert!(memmem::find(&data, b"foo-bar").is_some());

View File

@ -60,7 +60,7 @@ where
{ {
/// Create new `HttpService` instance. /// Create new `HttpService` instance.
pub fn new<F: IntoServiceFactory<S, Request>>(service: F) -> Self { 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 { HttpService {
cfg, cfg,

View File

@ -88,7 +88,7 @@ where
factory, factory,
config: Arc::new(Mutex::new(Config { config: Arc::new(Mutex::new(Config {
host: None, host: None,
keep_alive: KeepAlive::Timeout(5), keep_alive: KeepAlive::default(),
client_timeout: 5000, client_timeout: 5000,
client_shutdown: 5000, client_shutdown: 5000,
})), })),