yhirose 9 months ago
parent
commit
33acccb346
2 changed files with 6 additions and 2 deletions
  1. 3 2
      httplib.h
  2. 3 0
      test/test.cc

+ 3 - 2
httplib.h

@@ -4389,7 +4389,8 @@ inline bool read_content_without_length(Stream &strm,
   uint64_t r = 0;
   uint64_t r = 0;
   for (;;) {
   for (;;) {
     auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ);
     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<size_t>(n), r, 0)) { return false; }
     if (!out(buf, static_cast<size_t>(n), r, 0)) { return false; }
     r += static_cast<uint64_t>(n);
     r += static_cast<uint64_t>(n);
@@ -10492,4 +10493,4 @@ inline SSL_CTX *Client::ssl_context() const {
 
 
 } // namespace httplib
 } // namespace httplib
 
 
-#endif // CPPHTTPLIB_HTTPLIB_H
+#endif // CPPHTTPLIB_HTTPLIB_H

+ 3 - 0
test/test.cc

@@ -5571,6 +5571,9 @@ TEST(StreamingTest, NoContentLengthStreaming) {
           s += std::string(data, len);
           s += std::string(data, len);
           return true;
           return true;
         });
         });
+
+    ASSERT_TRUE(res);
+    EXPECT_EQ(StatusCode::OK_200, res->status);
     EXPECT_EQ("aaabbb", s);
     EXPECT_EQ("aaabbb", s);
   });
   });
   auto get_se = detail::scope_exit([&] { get_thread.join(); });
   auto get_se = detail::scope_exit([&] { get_thread.join(); });