Do not send empty chunk for HEAD requests

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/")
This commit is contained in:
Mindy Batek 2025-07-26 00:51:26 +02:00
parent b57bb91998
commit 4da8ec0ac4
1 changed files with 1 additions and 1 deletions

2
cgi.d
View File

@ -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)