From 4da8ec0ac40a63f9a7089f330b128cdc05d63974 Mon Sep 17 00:00:00 2001 From: Mindy Batek Date: Sat, 26 Jul 2025 00:51:26 +0200 Subject: [PATCH] Do not send empty chunk for HEAD requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HEAD requests are not supposed to have a body. MDN suggests that… > If a response to a HEAD request has a body, the response body must be ignored. Web browser seem to handle such situations well. Unfortunately, Node.js does not; instead it tries to parse the empty chunk as a new HTTP response and reports an error. (Code `HPE_INVALID_CONSTANT` with reason "Expected HTTP/") --- cgi.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgi.d b/cgi.d index 72cebbe..d1d2ad1 100644 --- a/cgi.d +++ b/cgi.d @@ -2735,7 +2735,7 @@ class Cgi { } // closing the last chunk... - if(nph && rawDataOutput !is null && responseChunked) + if(requestMethod != RequestMethod.HEAD && nph && rawDataOutput !is null && responseChunked) rawDataOutput(cast(const(ubyte)[]) "0\r\n\r\n"); if(flushDelegate)