mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-23 11:54:42 +00:00
Answer 501 to a request with a transfer coding besides chunked
A request whose Transfer-Encoding ended in chunked but listed more (another coding before chunked, or chunked twice) was read with only the chunked framing removed, so the handler got a body still in the other coding. RFC 9112 6.1 lets a server answer 501 to a transfer coding it does not implement. The server now accepts only a single Transfer-Encoding field whose value is chunked, as Go and nginx do, and answers any other list ending in chunked with 501 and closes the connection. A list whose final coding is not chunked still gets 400.
This commit is contained in:
1 parent
32a0ca8b35
commit
fbd3e2cc9b
2 files changed
+39
-22
No files matched your search
@@ -15135,6 +15135,16 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
return write_response(strm, close_connection, req, res);
|
||||
}
|
||||
|
||||
// RFC 9112 6.1: a lone "chunked" is the only transfer coding implemented
|
||||
if (req.has_header("Transfer-Encoding") &&
|
||||
(req.get_header_value_count("Transfer-Encoding") != 1 ||
|
||||
!detail::case_ignore::equal(req.get_header_value("Transfer-Encoding"),
|
||||
"chunked"))) {
|
||||
connection_closed = true;
|
||||
res.status = StatusCode::NotImplemented_501;
|
||||
return write_response(strm, close_connection, req, res);
|
||||
}
|
||||
|
||||
// RFC 9112 §6.1: a Transfer-Encoding alongside a Content-Length, or in an
|
||||
// HTTP/1.0 request, is honoured, but the connection closes after the
|
||||
// response.
|
||||
|
||||
Reference in new issue
Block a user