mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Match the Expect 100-continue expectation as a token
RFC 9110 Section 10.1.1 defines Expect as a comma-separated list, states that its value is case-insensitive, and requires a server that receives a 100-continue expectation in an HTTP/1.0 request to ignore it. Comparing the whole field value against "100-continue" met none of those. An HTTP/1.0 request asking for 100-continue was answered with a 100 (Continue) interim response, which that section forbids. "100-Continue" and "100-continue, foo" were both read as no expectation at all, so a client that waits for the interim response before sending its content waited for a response that was never coming. Route the check through has_header_token(), which walks every field line and compares complete tokens case-insensitively, and skip it for HTTP/1.0. An expectation cpp-httplib does not recognize is still ignored rather than refused; the 417 the section offers for one is a MAY, not a requirement.
This commit is contained in:
1 parent
3e3e4863b0
commit
f442226581
2 files changed
+95
-2
No files matched your search
@@ -13519,7 +13519,12 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
|
||||
if (setup_request) { setup_request(req); }
|
||||
|
||||
if (req.get_header_value("Expect") == "100-continue") {
|
||||
// RFC 9110 10.1.1: Expect is a comma-separated list whose value is
|
||||
// case-insensitive, and a 100-continue expectation in an HTTP/1.0 request
|
||||
// must be ignored. An expectation we do not recognize is left alone; the
|
||||
// 417 the section allows for one is a MAY, not a requirement.
|
||||
if (req.version != "HTTP/1.0" &&
|
||||
detail::has_header_token(req.headers, "Expect", "100-continue")) {
|
||||
int status = StatusCode::Continue_100;
|
||||
if (expect_100_continue_handler_) {
|
||||
status = expect_100_continue_handler_(req, res);
|
||||
@@ -15082,7 +15087,8 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
|
||||
}
|
||||
|
||||
// Check for Expect: 100-continue
|
||||
auto expect_100_continue = req.get_header_value("Expect") == "100-continue";
|
||||
auto expect_100_continue =
|
||||
detail::has_header_token(req.headers, "Expect", "100-continue");
|
||||
|
||||
// Send request (skip body if using Expect: 100-continue)
|
||||
auto write_request_success =
|
||||
|
||||
Reference in new issue
Block a user