Skip to content

Commit

Permalink
http: return Content-Length header for HEADs
Browse files Browse the repository at this point in the history
In the current http library, all responses without body will not return
the Content-Length header.

Fixes: #56680
  • Loading branch information
qwerzl committed Jan 22, 2025
1 parent 7bc2946 commit 8c4c5fc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function _storeHeader(firstLine, headers) {
}

if (!state.contLen && !state.te) {
if (!this._hasBody) {
if (!this._hasBody && this.req.method !== 'HEAD') {
// Make sure we don't end the 0\r\n\r\n at the end of the message.
this.chunkedEncoding = false;
} else if (!this.useChunkedEncodingByDefault) {
Expand Down Expand Up @@ -932,7 +932,7 @@ function strictContentLength(msg) {
return (
msg.strictContentLength &&
msg._contentLength != null &&
msg._hasBody &&
(msg._hasBody || msg.req.method === 'HEAD') &&
!msg._removedContLen &&
!msg.chunkedEncoding &&
!msg.hasHeader('transfer-encoding')
Expand Down

0 comments on commit 8c4c5fc

Please sign in to comment.