summaryrefslogtreecommitdiff
path: root/lib/http.js
diff options
context:
space:
mode:
authorReid Burke <me@reidburke.com>2011-07-07 21:04:27 -0700
committerkoichik <koichik@improvement.jp>2011-07-20 00:24:17 +0900
commit973153d1ccdbb06f9067f3698578e8a5685a87c4 (patch)
tree7a4171610eb7bd3d1942120cf138e4ba6c5184e2 /lib/http.js
parent9f9a4cb9284794cea04098735f0dcc4c771db153 (diff)
downloadnode-973153d1ccdbb06f9067f3698578e8a5685a87c4.tar.gz
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/http.js')
-rw-r--r--lib/http.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/http.js b/lib/http.js
index 14befd15d..e5291fbf9 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 +