Close the connection after an ambiguous Transfer-Encoding

RFC 9112 6.1 has a server close the connection after answering a
request with both Transfer-Encoding and Content-Length, or with
Transfer-Encoding in HTTP/1.0. Close it, and send Connection: close
whenever the connection closes after a response.
This commit is contained in:
yhirose committed 2026-10-16 16:39:00 -04:00
1 parent 64bebd3b2b
commit 58957ae4da
2 files changed
+36 -4

No files matched your search

+23
View File
@@ -10836,6 +10836,29 @@ TEST(ServerRequestParsingTest, ExcessiveWhitespaceInUnparsableHeaderLine) {
"\r\n");
}
TEST(ServerRequestParsingTest, AmbiguousTransferEncodingClosesConnection) {
// RFC 9112 §6.1
const char *requests[] = {
"PUT /put_hi HTTP/1.1\r\n"
"Content-Length: 0\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"
"0\r\n\r\n",
"PUT /put_hi HTTP/1.0\r\n"
"Connection: keep-alive\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"
"0\r\n\r\n",
};
for (auto request : requests) {
std::string out;
test_raw_request(request, &out);
EXPECT_EQ("HTTP/1.1 200 OK", out.substr(0, 15)) << request;
EXPECT_NE(std::string::npos, out.find("Connection: close")) << request;
}
}
TEST(ServerRequestParsingTest, InvalidFirstChunkLengthInRequest) {
std::string out;