From 03a577cccdd6bcdb7e2603dcbfe8fd5c91f2d1c2 Mon Sep 17 00:00:00 2001 From: yhirose Date: Tue, 7 May 2019 16:41:50 -0400 Subject: [PATCH] Fixed huge payload problem on Windows --- httplib.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/httplib.h b/httplib.h index 506df30..b962f83 100644 --- a/httplib.h +++ b/httplib.h @@ -851,6 +851,16 @@ inline bool read_content_with_length(Stream &strm, std::string &out, size_t len, return true; } +inline void skip_content_with_length(Stream &strm, size_t len) { + char buf[BUFSIZ]; + size_t r = 0; + while (r < len) { + auto n = strm.read(buf, BUFSIZ); + if (n <= 0) { return; } + r += n; + } +} + inline bool read_content_without_length(Stream &strm, std::string &out) { for (;;) { char byte; @@ -920,6 +930,7 @@ bool read_content(Stream &strm, T &x, uint64_t payload_max_length, (sizeof(size_t) < sizeof(uint64_t) && len > std::numeric_limits::max())) { exceed_payload_max_length = true; + skip_content_with_length(strm, len); return false; }