Skip to content

Commit

Permalink
Fixed #15
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Sep 8, 2017
1 parent 2a45bdc commit bfb7f7b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ inline bool read_headers(Stream& strm, MultiMap& headers)
}

template <typename T>
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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit bfb7f7b

Please sign in to comment.