From bfb7f7bb78482610b7ba1fb137a498473683c9c9 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 8 Sep 2017 12:59:00 -0400 Subject: [PATCH] Fixed #15 --- httplib.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/httplib.h b/httplib.h index ac630db..036fdd8 100644 --- a/httplib.h +++ b/httplib.h @@ -506,7 +506,7 @@ inline bool read_headers(Stream& strm, MultiMap& headers) } template -bool read_content(Stream& strm, T& x) +bool read_content(Stream& strm, T& x, bool allow_no_content_length) { auto len = get_header_value_int(x.headers, "Content-Length", 0); if (len) { @@ -519,6 +519,19 @@ bool read_content(Stream& strm, T& x) } r += r_incr; } + } else if (allow_no_content_length) { + for (;;) { + char byte; + auto n = strm.read(&byte, 1); + if (n < 1) { + if (x.body.size() == 0) { + return true; // no body + } else { + break; + } + } + x.body += byte; + } } return true; } @@ -980,7 +993,7 @@ inline void Server::process_request(Stream& strm) } if (req.method == "POST") { - if (!detail::read_content(strm, req)) { + if (!detail::read_content(strm, req, false)) { // TODO: return; } @@ -1068,7 +1081,7 @@ inline bool Client::process_request(Stream& strm, const Request& req, Response& return false; } if (req.method != "HEAD") { - if (!detail::read_content(strm, res)) { + if (!detail::read_content(strm, res, false)) { return false; } }