Treat a zero payload limit as none when decompressing a stream

set_payload_max_length(0) means no limit, but StreamHandle compared the
decompressed size against 0, so every compressed response read through
the streaming API failed.
This commit is contained in:
yhirose committed 2026-10-16 16:39:00 -04:00
1 parent d41d5586cf
commit 194f392417
2 files changed
+13 -4

No files matched your search

+2 -4
View File
@@ -15598,10 +15598,8 @@ inline ssize_t ClientImpl::StreamHandle::read_with_decompression(char *buf,
[this](const char *data, size_t data_len) {
decompress_buffer_.append(data, data_len);
auto limit = body_reader_.payload_max_length;
if (decompressed_bytes_read_ + decompress_buffer_.size() > limit) {
return false;
}
return true;
return limit == 0 ||
decompressed_bytes_read_ + decompress_buffer_.size() <= limit;
});
if (!decompress_ok) {
+11
View File
@@ -22411,6 +22411,17 @@ TEST_F(StreamApiTest, GetWithParams) {
EXPECT_TRUE(read_body(result).find("foo=bar") != std::string::npos);
}
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
TEST_F(StreamApiTest, GetCompressedWithNoPayloadLimit) {
httplib::Client cli(HOST, PORT);
cli.set_payload_max_length(0);
auto result = httplib::stream::Get(cli, "/hello");
ASSERT_TRUE(result.is_valid());
EXPECT_FALSE(result.get_header_value("Content-Encoding").empty());
EXPECT_EQ("Hello World!", read_body(result));
}
#endif
TEST_F(StreamApiTest, GetConnectionError) {
httplib::Client cli(HOST, 9999);
EXPECT_FALSE(httplib::stream::Get(cli, "/hello").is_valid());