Bound the number of interim responses a client skips

A server sending "102 Processing" without end kept the client reading
them unless max_timeout was set. Skip at most
CPPHTTPLIB_INTERIM_RESPONSE_MAX_COUNT (100) and fail with Error::Read
past it.
This commit is contained in:
yhirose committed 2026-10-16 23:52:15 -04:00
1 parent 560126bffc
commit 8ca46a4db5
2 files changed
+32 -1

No files matched your search

+22
View File
@@ -23031,6 +23031,28 @@ TEST(InterimResponseTest, SkippedWithTheirHeaderFields) {
}
}
TEST(InterimResponseTest, OnlySoManyAreSkipped) {
const std::string interim = "HTTP/1.1 102 Processing\r\n\r\n";
const std::string final_response =
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok";
std::string interims;
for (auto i = 0; i < CPPHTTPLIB_INTERIM_RESPONSE_MAX_COUNT; i++) {
interims += interim;
}
with_single_response(interims + final_response, [](Client &cli) {
auto res = cli.Get("/");
ASSERT_TRUE(res) << "Error: " << to_string(res.error());
EXPECT_EQ("ok", res->body);
});
with_single_response(interims + interim + final_response, [](Client &cli) {
auto res = cli.Get("/");
ASSERT_FALSE(res);
EXPECT_EQ(Error::Read, res.error());
});
}
TEST(ExpectContinueTest, EarlyFinalResponseClosesConnection) {
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);