Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: return Content-Length header for HEADs #56681

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');

// This test is to make sure that when the HTTP server
// responds to a HEAD request with data to res.end,
Expand All @@ -18,6 +19,8 @@
method: 'HEAD',
path: '/'
}, common.mustCall(function(res) {
assert(res.headers['content-length'] !== undefined, 'Content-Length header is missing');

Check failure on line 22 in test/parallel/test-http-head-response-has-no-body-end-implicit-headers.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'assert.notStrictEqual' should be used instead of '!=='

res.on('end', common.mustCall(function() {
server.close();
}));
Expand Down
Loading