Skip to content

Commit 7435cc3

Browse files
authoredNov 30, 2021
fix(server): use case-insensitive comparison for Expect: 100-continue (#2709)
According to rfc2616#section-14.20 the header value is case-insensitive. Certain clients send the expectation as `100-Continue` and this should be handled by the server. Closes #2708
1 parent 5f938ff commit 7435cc3

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎src/proto/h1/role.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ impl Http1Transaction for Server {
271271
}
272272
}
273273
header::EXPECT => {
274-
expect_continue = value.as_bytes() == b"100-continue";
274+
// According to https://datatracker.ietf.org/doc/html/rfc2616#section-14.20
275+
// Comparison of expectation values is case-insensitive for unquoted tokens
276+
// (including the 100-continue token)
277+
expect_continue = value.as_bytes().eq_ignore_ascii_case(b"100-continue");
275278
}
276279
header::UPGRADE => {
277280
// Upgrades are only allowed with HTTP/1.1

‎tests/server.rs

+33
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,39 @@ fn expect_continue_sends_100() {
831831
assert_eq!(body, msg);
832832
}
833833

834+
#[test]
835+
fn expect_continue_accepts_upper_cased_expectation() {
836+
let server = serve();
837+
let mut req = connect(server.addr());
838+
server.reply();
839+
840+
req.write_all(
841+
b"\
842+
POST /foo HTTP/1.1\r\n\
843+
Host: example.domain\r\n\
844+
Expect: 100-Continue\r\n\
845+
Content-Length: 5\r\n\
846+
Connection: Close\r\n\
847+
\r\n\
848+
",
849+
)
850+
.expect("write 1");
851+
852+
let msg = b"HTTP/1.1 100 Continue\r\n\r\n";
853+
let mut buf = vec![0; msg.len()];
854+
req.read_exact(&mut buf).expect("read 1");
855+
assert_eq!(buf, msg);
856+
857+
let msg = b"hello";
858+
req.write_all(msg).expect("write 2");
859+
860+
let mut body = String::new();
861+
req.read_to_string(&mut body).expect("read 2");
862+
863+
let body = server.body();
864+
assert_eq!(body, msg);
865+
}
866+
834867
#[test]
835868
fn expect_continue_but_no_body_is_ignored() {
836869
let server = serve();

0 commit comments

Comments
 (0)
Please sign in to comment.