From 7adbccbaf71c28195949a67350f721da44a32896 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 8 Feb 2025 21:51:52 +0100 Subject: [PATCH] Refine when content is expected (#2044) Consider Content-Length and Transfer-Encoding headers when determining whether to expect content. Don't handle the HTTP/2 connection preface pseudo-method PRI. Fixes #2028. --- httplib.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/httplib.h b/httplib.h index 5c649c4..257d9eb 100644 --- a/httplib.h +++ b/httplib.h @@ -5381,10 +5381,14 @@ write_multipart_ranges_data(Stream &strm, const Request &req, Response &res, inline bool expect_content(const Request &req) { if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" || - req.method == "PRI" || req.method == "DELETE") { + req.method == "DELETE") { return true; } - // TODO: check if Content-Length is set + if (req.has_header("Content-Length") && + req.get_header_value_u64("Content-Length") > 0) { + return true; + } + if (is_chunked_transfer_encoding(req.headers)) { return true; } return false; }