From 838e8b2b6b2546ec4733667ed9e126382c75c241 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 22 Aug 2023 16:31:21 +0800 Subject: [PATCH] fix(server): Respect Expect header only when http proto > 1.0 --- src/proto/h1/conn.rs | 2 +- tests/server.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index e0d65bd2d4..04f25ef085 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -257,7 +257,7 @@ where if !T::should_read_first() { self.try_keep_alive(cx); } - } else if msg.expect_continue { + } else if msg.expect_continue && msg.head.version.gt(&Version::HTTP_10) { self.state.reading = Reading::Continue(Decoder::new(msg.decode)); wants = wants.add(Wants::EXPECT); } else { diff --git a/tests/server.rs b/tests/server.rs index 98ded22d73..4a514907db 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -916,6 +916,39 @@ fn expect_continue_accepts_upper_cased_expectation() { assert_eq!(body, msg); } +#[test] +fn expect_continue_but_http_10_is_ignored() { + let server = serve(); + let mut req = connect(server.addr()); + server.reply(); + + req.write_all( + b"\ + POST /foo HTTP/1.0\r\n\ + Host: example.domain\r\n\ + Expect: 100-Continue\r\n\ + Content-Length: 5\r\n\ + Connection: Close\r\n\ + \r\n\ + ", + ) + .expect("write 1"); + + let msg = b"hello"; + req.write_all(msg).expect("write 2"); + + let s_line = b"HTTP/1.0 200 OK\r\n"; + let mut buf = vec![0; s_line.len()]; + req.read_exact(&mut buf).expect("read 1"); + assert_eq!(buf, s_line); + + let mut body = String::new(); + req.read_to_string(&mut body).expect("read 2"); + + let body = server.body(); + assert_eq!(body, msg); +} + #[test] fn expect_continue_but_no_body_is_ignored() { let server = serve();