diff options
author | Reid Burke <me@reidburke.com> | 2011-07-08 08:04:27 +0400 |
---|---|---|
committer | koichik <koichik@improvement.jp> | 2011-07-19 19:24:17 +0400 |
commit | 973153d1ccdbb06f9067f3698578e8a5685a87c4 (patch) | |
tree | 7a4171610eb7bd3d1942120cf138e4ba6c5184e2 /lib | |
parent | 9f9a4cb9284794cea04098735f0dcc4c771db153 (diff) |
Properly respond to HEAD during end(body) hot path
During write(), _hasBody is checked to make sure a body
is allowed -- this is now also checked during end(body)
when write() isn't used.
Concise final chunk for HEAD req's res.end(data).
Instead of simply clearing data, check _hasBody
earlier to avoid sending cruft when chunkedEncoding
is used.
Fixes #1291.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http.js | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/http.js b/lib/http.js index 14befd15dfe..e5291fbf9a9 100644 --- a/lib/http.js +++ b/lib/http.js @@ -652,6 +652,12 @@ OutgoingMessage.prototype.end = function(data, encoding) { this._implicitHeader(); } + if (data && !this._hasBody) { + console.error('This type of response MUST NOT have a body. ' + + 'Ignoring data passed to end().'); + data = false; + } + var ret; var hot = this._headerSent === false && @@ -667,6 +673,7 @@ OutgoingMessage.prototype.end = function(data, encoding) { // res.writeHead(); // res.end(blah); // HACKY. + if (this.chunkedEncoding) { var l = Buffer.byteLength(data, encoding).toString(16); ret = this.connection.write(this._header + l + CRLF + |