Skip to content

Commit ecc1628

Browse files
Refine when content is expected
Consider Content-Length and Transfer-Encoding headers when determining whether to expect content. Don't expect content for DELETE requests and don't handle the HTTP/2 connection preface pseudo-method PRI. Fixes #2028.
1 parent 708f860 commit ecc1628

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

httplib.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5380,11 +5380,14 @@ write_multipart_ranges_data(Stream &strm, const Request &req, Response &res,
53805380
}
53815381

53825382
inline bool expect_content(const Request &req) {
5383-
if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" ||
5384-
req.method == "PRI" || req.method == "DELETE") {
5383+
if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH") {
53855384
return true;
53865385
}
5387-
// TODO: check if Content-Length is set
5386+
if (req.has_header("Content-Length") &&
5387+
req.get_header_value_u64("Content-Length") > 0) {
5388+
return true;
5389+
}
5390+
if (is_chunked_transfer_encoding(req.headers)) { return true; }
53885391
return false;
53895392
}
53905393

0 commit comments

Comments
 (0)