From 33acccb346ec336b3b3b10d3b0f22884615a35e9 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sun, 16 Mar 2025 20:29:54 -0400 Subject: [PATCH] Fix #2109 --- httplib.h | 5 +++-- test/test.cc | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/httplib.h b/httplib.h index 60686e3..9c2f3ec 100644 --- a/httplib.h +++ b/httplib.h @@ -4389,7 +4389,8 @@ inline bool read_content_without_length(Stream &strm, uint64_t r = 0; for (;;) { auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ); - if (n <= 0) { return false; } + if (n == 0) { return true; } + if (n < 0) { return false; } if (!out(buf, static_cast(n), r, 0)) { return false; } r += static_cast(n); @@ -10492,4 +10493,4 @@ inline SSL_CTX *Client::ssl_context() const { } // namespace httplib -#endif // CPPHTTPLIB_HTTPLIB_H \ No newline at end of file +#endif // CPPHTTPLIB_HTTPLIB_H diff --git a/test/test.cc b/test/test.cc index 725af16..acbd11a 100644 --- a/test/test.cc +++ b/test/test.cc @@ -5571,6 +5571,9 @@ TEST(StreamingTest, NoContentLengthStreaming) { s += std::string(data, len); return true; }); + + ASSERT_TRUE(res); + EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ("aaabbb", s); }); auto get_se = detail::scope_exit([&] { get_thread.join(); });