summaryrefslogtreecommitdiff
path: root/lib/http.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-01-23 01:42:16 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2013-01-23 01:47:24 +0100
commit2cbf4586df837e6b2cc7e04f7b9ae7766904df61 (patch)
treecad27e11925f4cf09dcb09a04c1f32ab819f5a44 /lib/http.js
parente2acf26a91c68df83720b735d1abf484b967afb7 (diff)
downloadandroid-node-v8-2cbf4586df837e6b2cc7e04f7b9ae7766904df61.tar.gz
android-node-v8-2cbf4586df837e6b2cc7e04f7b9ae7766904df61.tar.bz2
android-node-v8-2cbf4586df837e6b2cc7e04f7b9ae7766904df61.zip
http: close connection on 304 and chunked encoding
Force the connection to close when the response is a 304 Not Modified and the user has set a "Transfer-Encoding: chunked" header. RFC 2616 mandates that 304 responses MUST NOT have a body but node.js used to send out a zero chunk anyway to accommodate clients that don't have special handling for 304 responses. It was pointed out that this might confuse reverse proxies to the point of creating security liabilities, so suppress the zero chunk and force the connection to close.
Diffstat (limited to 'lib/http.js')
-rw-r--r--lib/http.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/http.js b/lib/http.js
index c8bec11212..6b774c3c68 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -564,6 +564,22 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
state.messageHeader += 'Date: ' + utcDate() + CRLF;
}
+ // Force the connection to close when the response is a 304 Not Modified
+ // and the user has set a "Transfer-Encoding: chunked" header.
+ //
+ // RFC 2616 mandates that 304 responses MUST NOT have a body but node.js
+ // used to send out a zero chunk anyway to accommodate clients that don't
+ // have special handling for 304 responses.
+ //
+ // It was pointed out that this might confuse reverse proxies to the point
+ // of creating security liabilities, so suppress the zero chunk and force
+ // the connection to close.
+ if (this.statusCode === 304 && this.chunkedEncoding === true) {
+ debug('304 response should not use chunked encoding, closing connection.');
+ this.chunkedEncoding = false;
+ this.shouldKeepAlive = false;
+ }
+
// keep-alive logic
if (state.sentConnectionHeader === false) {
var shouldSendKeepAlive = this.shouldKeepAlive &&