Skip to content

Commit 43d2f5c

Browse files
authoredAug 23, 2023
fix(server): Respect Expect header only when http proto > 1.0 (#3294)
1 parent fece9f7 commit 43d2f5c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎src/proto/h1/conn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ where
257257
if !T::should_read_first() {
258258
self.try_keep_alive(cx);
259259
}
260-
} else if msg.expect_continue {
260+
} else if msg.expect_continue && msg.head.version.gt(&Version::HTTP_10) {
261261
self.state.reading = Reading::Continue(Decoder::new(msg.decode));
262262
wants = wants.add(Wants::EXPECT);
263263
} else {

‎tests/server.rs

+33
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,39 @@ fn expect_continue_accepts_upper_cased_expectation() {
916916
assert_eq!(body, msg);
917917
}
918918

919+
#[test]
920+
fn expect_continue_but_http_10_is_ignored() {
921+
let server = serve();
922+
let mut req = connect(server.addr());
923+
server.reply();
924+
925+
req.write_all(
926+
b"\
927+
POST /foo HTTP/1.0\r\n\
928+
Host: example.domain\r\n\
929+
Expect: 100-Continue\r\n\
930+
Content-Length: 5\r\n\
931+
Connection: Close\r\n\
932+
\r\n\
933+
",
934+
)
935+
.expect("write 1");
936+
937+
let msg = b"hello";
938+
req.write_all(msg).expect("write 2");
939+
940+
let s_line = b"HTTP/1.0 200 OK\r\n";
941+
let mut buf = vec![0; s_line.len()];
942+
req.read_exact(&mut buf).expect("read 1");
943+
assert_eq!(buf, s_line);
944+
945+
let mut body = String::new();
946+
req.read_to_string(&mut body).expect("read 2");
947+
948+
let body = server.body();
949+
assert_eq!(body, msg);
950+
}
951+
919952
#[test]
920953
fn expect_continue_but_no_body_is_ignored() {
921954
let server = serve();

0 commit comments

Comments
 (0)
Please sign in to comment.