diff options
author | Fedor Indutny <fedor@indutny.com> | 2014-09-13 13:08:25 +0100 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2014-09-16 15:24:19 -0700 |
commit | 1fddc1fee84785d296e37337dcb0dc12c13a049f (patch) | |
tree | 92eac4663cbfabd1476e20c63e32935904d01dd4 /lib | |
parent | 6e689ece46726f39bdf93f1f35e01656f8fe27dc (diff) | |
download | nodejs-1fddc1fee84785d296e37337dcb0dc12c13a049f.tar.gz nodejs-1fddc1fee84785d296e37337dcb0dc12c13a049f.tar.bz2 nodejs-1fddc1fee84785d296e37337dcb0dc12c13a049f.zip |
http: do not send `0\r\n\r\n` in TE HEAD responses
When replying to a HEAD request, do not attempt to send the trailers and
EOF sequence (`0\r\n\r\n`). The HEAD request MUST not have body.
Quote from RFC:
The presence of a message body in a response depends on both the
request method to which it is responding and the response status code
(Section 3.1.2). Responses to the HEAD request method (Section 4.3.2
of [RFC7231]) never include a message body because the associated
response header fields (e.g., Transfer-Encoding, Content-Length,
etc.), if present, indicate only what their values would have been if
the request method had been GET (Section 4.3.1 of [RFC7231]).
fix #8361
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/http.js b/lib/http.js index 0623668c9..f87df173b 100644 --- a/lib/http.js +++ b/lib/http.js @@ -945,6 +945,10 @@ OutgoingMessage.prototype.end = function(data, encoding) { if (encoding === 'hex' || encoding === 'base64') hot = false; + // Transfer-encoding: chunked responses to HEAD requests + if (this._hasBody && this.chunkedEncoding) + hot = false; + if (hot) { // Hot path. They're doing // res.writeHead(); @@ -982,7 +986,7 @@ OutgoingMessage.prototype.end = function(data, encoding) { } if (!hot) { - if (this.chunkedEncoding) { + if (this._hasBody && this.chunkedEncoding) { ret = this._send('0\r\n' + this._trailer + '\r\n', 'ascii'); } else { // Force a flush, HACK. |