Skip to content

Commit

Permalink
fix(server): Respect Expect header only when http proto > 1.0 (#3294)
Browse files Browse the repository at this point in the history
  • Loading branch information
owarai authored Aug 23, 2023
1 parent fece9f7 commit 43d2f5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 43d2f5c

Please sign in to comment.