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