From 1ed8ea0431d0521a353c49e718cdb13b22b2bd7e Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Tue, 14 Jan 2025 11:00:52 -0800 Subject: [PATCH] Test new functionality. --- tests/server.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/server.rs b/tests/server.rs index 7edf858073..2ba6f92ca3 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1632,6 +1632,50 @@ async fn header_read_timeout_slow_writes_multiple_requests() { assert!(conn.without_shutdown().await.unwrap_err().is_timeout()); } +#[tokio::test] +async fn header_read_timeout_as_idle_timeout() { + let (listener, addr) = setup_tcp_listener(); + + thread::spawn(move || { + let mut tcp = connect(&addr); + + tcp.write_all( + b"\ + GET / HTTP/1.1\r\n\ + \r\n\ + ", + ) + .expect("request 1"); + + thread::sleep(Duration::from_secs(6)); + + tcp.write_all( + b"\ + GET / HTTP/1.1\r\n\ + \r\n\ + ", + ) + .expect_err("request 2"); + }); + + let (socket, _) = listener.accept().await.unwrap(); + let socket = TokioIo::new(socket); + let conn = http1::Builder::new() + .timer(TokioTimer) + .header_read_timeout(Duration::from_secs(3)) + .serve_connection( + socket, + service_fn(|_| { + let res = Response::builder() + .status(200) + .body(Empty::::new()) + .unwrap(); + future::ready(Ok::<_, hyper::Error>(res)) + }), + ); + assert!(conn.without_shutdown().await.unwrap_err().is_timeout()); +} + #[tokio::test] async fn upgrades() { let (listener, addr) = setup_tcp_listener();