Report a response body over the limit as ExceedMaxPayloadSize

A buffered request whose response body went over set_payload_max_length(),
also once decompressed, failed with Error::Read, while the Stream API
reports the same limit as Error::ExceedMaxPayloadSize. read_content()
already marks it with a 413 status, so map that status to
ExceedMaxPayloadSize next to the 415 and 500 the client maps already.
This commit is contained in:
yhirose committed 2026-10-18 18:40:23 -04:00
1 parent 344aceb446
commit d99c697be6
5 files changed
+43 -2

No files matched your search

+33
View File
@@ -14389,6 +14389,39 @@ TEST(ClientPayloadTest, DoesNotReserveTheClaimedLength) {
EXPECT_FALSE(cli.Get("/"));
}
// A response body over the limit is reported as ExceedMaxPayloadSize, as the
// Stream API does, not as a plain read failure
TEST(ClientPayloadTest, OverLimitIsExceedMaxPayloadSize) {
Server svr;
svr.Get("/big", [](const Request &, Response &res) {
res.set_content(std::string(100000, 'b'), "text/plain");
});
auto port = svr.bind_to_any_port(HOST);
auto thread = std::thread([&]() { svr.listen_after_bind(); });
auto se = detail::scope_exit([&] {
svr.stop();
thread.join();
});
svr.wait_until_ready();
Client cli(HOST, port);
cli.set_payload_max_length(1000);
auto res = cli.Get("/big", Headers{{"Accept-Encoding", ""}});
EXPECT_EQ(Error::ExceedMaxPayloadSize, res.error());
res = cli.Get("/big", Headers{{"Accept-Encoding", ""}},
[](const char *, size_t) { return true; });
EXPECT_EQ(Error::ExceedMaxPayloadSize, res.error());
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
// Small on the wire, over the limit once decompressed
res = cli.Get("/big", Headers{{"Accept-Encoding", "gzip"}});
EXPECT_EQ(Error::ExceedMaxPayloadSize, res.error());
#endif
}
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
// `payload_max_length` is not enforced on decompressed body in ContentReader
// path.