Skip to content

Commit

Permalink
http: correcting Content-Length header behavior on HEAD
Browse files Browse the repository at this point in the history
Currently there's a slight perverse interaction between code intended
to prevent sending a null-chunk on 204/304 response codes and socket
re-use. HEAD requests can re-use a socket, apparently if and only if
they have either content-length or content-encoding headers, or the
response status is 204. The objective of this slight change is to
allow non-204 responses without bodies (e.g. in response to HEAD) to
set the payload headers that would have been sent normally. Both the
old and new behaviors are compliant with RFC7231 (see 4.3.2) and
RFC2616 (see 14.13).

Refs: https://tools.ietf.org/html/rfc7231#section-3.3
Refs: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Fixes: #28438
  • Loading branch information
josephhackman committed Jul 6, 2020
1 parent 01ec301 commit 9e30728
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ function _storeHeader(firstLine, headers) {
}

if (!state.contLen && !state.te) {
if (!this._hasBody) {
if (!this._hasBody && (this.statusCode === 204 ||
this.statusCode === 304)) {
// 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

0 comments on commit 9e30728

Please sign in to comment.