diff --git a/FORK.md b/FORK.md index 70609ecc..7e8b0a8b 100644 --- a/FORK.md +++ b/FORK.md @@ -10,7 +10,7 @@ as a distant relative. ### hyperium - -- +- - ### tower-r diff --git a/rama-http-core/src/proto/h1/decode.rs b/rama-http-core/src/proto/h1/decode.rs index 0bfa0020..6671cc1a 100644 --- a/rama-http-core/src/proto/h1/decode.rs +++ b/rama-http-core/src/proto/h1/decode.rs @@ -771,7 +771,7 @@ mod tests { }) .await; let desc = format!("read_size failed for {:?}", s); - state = result.unwrap_or_else(|_| panic!("{}", desc)); + state = result.expect(&desc); if state == ChunkedState::Body || state == ChunkedState::EndCr { break; } diff --git a/rama-http-core/src/proto/h1/io.rs b/rama-http-core/src/proto/h1/io.rs index be98c4e5..696552f7 100644 --- a/rama-http-core/src/proto/h1/io.rs +++ b/rama-http-core/src/proto/h1/io.rs @@ -196,7 +196,11 @@ where return Poll::Ready(Err(crate::Error::new_too_large())); } if curr_len > 0 { + trace!("partial headers; {} bytes so far", curr_len); self.partial_len = Some(curr_len); + } else { + // 1xx gobled some bytes + self.partial_len = None; } } } diff --git a/rama-http-core/src/proto/h1/role.rs b/rama-http-core/src/proto/h1/role.rs index 9b6248c7..ed925337 100644 --- a/rama-http-core/src/proto/h1/role.rs +++ b/rama-http-core/src/proto/h1/role.rs @@ -667,12 +667,14 @@ impl Server { #[cfg(debug_assertions)] { if let Some(len) = headers::content_length_parse(&value) { - assert!( + if msg.req_method != &Some(Method::HEAD) || known_len != 0 { + assert!( len == known_len, "payload claims content-length of {}, custom content-length header claims {}", known_len, len, ); + } } } diff --git a/rama-http-core/src/proto/h2/ping.rs b/rama-http-core/src/proto/h2/ping.rs index 4105b6fd..b608c359 100644 --- a/rama-http-core/src/proto/h2/ping.rs +++ b/rama-http-core/src/proto/h2/ping.rs @@ -10,14 +10,14 @@ /// # BDP Algorithm /// /// 1. When receiving a DATA frame, if a BDP ping isn't outstanding: -/// - 1a. Record current time. -/// - 1b. Send a BDP ping. +/// 1a. Record current time. +/// 1b. Send a BDP ping. /// 2. Increment the number of received bytes. /// 3. When the BDP ping ack is received: -/// - 3a. Record duration from sent time. -/// - 3b. Merge RTT with a running average. -/// - 3c. Calculate bdp as bytes/rtt. -/// - 3d. If bdp is over 2/3 max, set new max to bdp and update windows. +/// 3a. Record duration from sent time. +/// 3b. Merge RTT with a running average. +/// 3c. Calculate bdp as bytes/rtt. +/// 3d. If bdp is over 2/3 max, set new max to bdp and update windows. use std::fmt; use std::future::Future; use std::pin::Pin; diff --git a/tests/http-core/client.rs b/tests/http-core/client.rs index 657f3897..225178ae 100644 --- a/tests/http-core/client.rs +++ b/tests/http-core/client.rs @@ -2032,6 +2032,63 @@ mod conn { assert_eq!(vec, b"bar=foo"); } + #[tokio::test] + async fn client_100_then_http09() { + let (server, addr) = setup_std_test_server(); + + thread::spawn(move || { + let mut sock = server.accept().unwrap().0; + sock.set_read_timeout(Some(Duration::from_secs(5))).unwrap(); + sock.set_write_timeout(Some(Duration::from_secs(5))) + .unwrap(); + let mut buf = [0; 4096]; + let _ = sock.read(&mut buf).expect("read 1"); + sock.write_all( + b"\ + HTTP/1.1 100 Continue\r\n\ + Content-Type: text/plain\r\n\ + Server: BaseHTTP/0.6 Python/3.12.5\r\n\ + Date: Mon, 16 Dec 2024 03:08:27 GMT\r\n\ + ", + ) + .unwrap(); + // That it's separate writes is important to this test + thread::sleep(Duration::from_millis(50)); + sock.write_all( + b"\ + \r\n\ + ", + ) + .expect("write 2"); + thread::sleep(Duration::from_millis(50)); + sock.write_all( + b"\ + This is a sample text/plain document, without final headers.\ + \n\n\ + ", + ) + .expect("write 3"); + }); + + let tcp = tcp_connect(&addr).await.unwrap(); + + let (mut client, conn) = conn::http1::Builder::new() + .http09_responses(true) + .handshake(tcp) + .await + .unwrap(); + + tokio::spawn(async move { + let _ = conn.await; + }); + + let req = Request::builder() + .uri("/a") + .body(Empty::::new()) + .unwrap(); + let _res = client.send_request(req).await.expect("send_request"); + } + #[tokio::test] async fn test_try_send_request() { use std::future::Future; diff --git a/tests/http-core/server.rs b/tests/http-core/server.rs index 8fcab302..34c0ef91 100644 --- a/tests/http-core/server.rs +++ b/tests/http-core/server.rs @@ -1467,7 +1467,7 @@ fn header_name_too_long() { let mut req = connect(server.addr()); let mut write = Vec::with_capacity(1024 * 66); write.extend_from_slice(b"GET / HTTP/1.1\r\n"); - write.resize(1024 * 65 - 1, b'x'); + write.extend_from_slice(vec![b'x'; 1024 * 64].as_slice()); write.extend_from_slice(b": foo\r\n\r\n"); req.write_all(&write).unwrap();