Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Respect Expect header only when http proto > 1.0 #3294

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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