mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
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:
1 parent
64bebd3b2b
commit
58957ae4da
2 files changed
+36
-4
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user