Allow longer response header fields than request header fields

The client read response header fields under CPPHTTPLIB_HEADER_MAX_LENGTH
(8192), the limit meant for requests a server accepts. Real servers now
send longer fields: www.youtube.com returns a 13KB
connection-allowlist-report-only field, so every request to it failed
with Error::Read.

Read response headers under a separate CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH,
32768 by default, and keep the request limit as it is.
This commit is contained in:
yhirose committed 2026-12-01 23:41:33 -05:00
1 parent a95f17cffa
commit 012a9871b1
2 files changed
+51 -8

No files matched your search

+30
View File
@@ -25415,6 +25415,36 @@ TEST(SSLClientTest, UnframedBodyEndsOnlyAtCloseNotify) {
}
#endif
TEST(ResponseHeaderLengthTest, ClientReadsLongerFieldsThanServer) {
const auto value = std::string(CPPHTTPLIB_HEADER_MAX_LENGTH * 2, 'a');
const auto response = "HTTP/1.1 200 OK\r\n"
"X-Long: " +
value +
"\r\n"
"Content-Length: 2\r\n"
"Connection: close\r\n\r\nok";
with_single_response(response, [&](Client &cli) {
auto res = cli.Get("/");
ASSERT_TRUE(res) << to_string(res.error());
EXPECT_EQ(value, res->get_header_value("X-Long"));
});
with_single_response(response, [&](Client &cli) {
auto handle = cli.open_stream("GET", "/");
ASSERT_TRUE(handle.is_valid()) << to_string(handle.error);
EXPECT_EQ(value, handle.response->get_header_value("X-Long"));
});
std::string out;
test_raw_request("GET /hi HTTP/1.1\r\n"
"Host: localhost\r\n"
"X-Long: " +
value + "\r\n\r\n",
&out);
EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24));
}
TEST(InterimResponseTest, SkippedWithTheirHeaderFields) {
const char *responses[] = {
"HTTP/1.1 103 Early Hints\r\n"