mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-26 12:24:46 +00:00
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:
1 parent
d41d5586cf
commit
194f392417
2 files changed
+13
-4
No files matched your search
@@ -15598,10 +15598,8 @@ inline ssize_t ClientImpl::StreamHandle::read_with_decompression(char *buf,
|
|||||||
[this](const char *data, size_t data_len) {
|
[this](const char *data, size_t data_len) {
|
||||||
decompress_buffer_.append(data, data_len);
|
decompress_buffer_.append(data, data_len);
|
||||||
auto limit = body_reader_.payload_max_length;
|
auto limit = body_reader_.payload_max_length;
|
||||||
if (decompressed_bytes_read_ + decompress_buffer_.size() > limit) {
|
return limit == 0 ||
|
||||||
return false;
|
decompressed_bytes_read_ + decompress_buffer_.size() <= limit;
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!decompress_ok) {
|
if (!decompress_ok) {
|
||||||
|
|||||||
@@ -22411,6 +22411,17 @@ TEST_F(StreamApiTest, GetWithParams) {
|
|||||||
EXPECT_TRUE(read_body(result).find("foo=bar") != std::string::npos);
|
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) {
|
TEST_F(StreamApiTest, GetConnectionError) {
|
||||||
httplib::Client cli(HOST, 9999);
|
httplib::Client cli(HOST, 9999);
|
||||||
EXPECT_FALSE(httplib::stream::Get(cli, "/hello").is_valid());
|
EXPECT_FALSE(httplib::stream::Get(cli, "/hello").is_valid());
|
||||||
|
|||||||
Reference in new issue
Block a user