Fixed #15
This commit is contained in:
parent
2a45bdcd3b
commit
bfb7f7bb78
19
httplib.h
19
httplib.h
@ -506,7 +506,7 @@ inline bool read_headers(Stream& strm, MultiMap& headers)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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);
|
auto len = get_header_value_int(x.headers, "Content-Length", 0);
|
||||||
if (len) {
|
if (len) {
|
||||||
@ -519,6 +519,19 @@ bool read_content(Stream& strm, T& x)
|
|||||||
}
|
}
|
||||||
r += r_incr;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -980,7 +993,7 @@ inline void Server::process_request(Stream& strm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.method == "POST") {
|
if (req.method == "POST") {
|
||||||
if (!detail::read_content(strm, req)) {
|
if (!detail::read_content(strm, req, false)) {
|
||||||
// TODO:
|
// TODO:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1068,7 +1081,7 @@ inline bool Client::process_request(Stream& strm, const Request& req, Response&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (req.method != "HEAD") {
|
if (req.method != "HEAD") {
|
||||||
if (!detail::read_content(strm, res)) {
|
if (!detail::read_content(strm, res, false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user