From 6cdd3493a147605290df5cc66dcc5b6f2a21db8f Mon Sep 17 00:00:00 2001 From: yhirose Date: Sun, 1 Sep 2024 01:55:27 -0400 Subject: [PATCH] Fix #1788 --- httplib.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/httplib.h b/httplib.h index 7b7b3f2..97c71a9 100644 --- a/httplib.h +++ b/httplib.h @@ -7720,6 +7720,14 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req, return ret; }; + if (res.has_header("Content-Length")) { + if (!req.content_receiver) { + auto len = std::min(res.get_header_value_u64("Content-Length"), + res.body.max_size()); + if (len > 0) { res.body.reserve(len); } + } + } + int dummy_status; if (!detail::read_content(strm, res, (std::numeric_limits::max)(), dummy_status, std::move(progress), std::move(out),