diff options
author | James Halliday <mail@substack.net> | 2012-09-09 19:04:37 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-08-19 16:05:44 -0700 |
commit | 5555318bf375a3edc17179b09b0bff1bfa9b6253 (patch) | |
tree | 9c34c6c776b2c1a03193615f26c1cf092febf7b5 /lib | |
parent | fe0f12b100c4cf33db42eab561f4bca8875909ad (diff) | |
download | nodejs-5555318bf375a3edc17179b09b0bff1bfa9b6253.tar.gz nodejs-5555318bf375a3edc17179b09b0bff1bfa9b6253.tar.bz2 nodejs-5555318bf375a3edc17179b09b0bff1bfa9b6253.zip |
http: removed headers stay removed
This allows automatically-inserted headers to be removed permanently by
calling OutgoingMessage.removeHeader() on them, as if they were normal
headers.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_http_outgoing.js | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 635e79490..b1e2dff50 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -38,6 +38,13 @@ var contentLengthExpression = /Content-Length/i; var dateExpression = /Date/i; var expectExpression = /Expect/i; +var automaticHeaders = { + connection: true, + 'content-length': true, + 'transfer-encoding': true, + date: true +}; + var dateCache; function utcDate() { @@ -68,6 +75,7 @@ function OutgoingMessage() { this.shouldKeepAlive = true; this.useChunkedEncodingByDefault = true; this.sendDate = false; + this._removedHeader = {}; this._hasBody = true; this._trailer = ''; @@ -245,7 +253,10 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) { } // keep-alive logic - if (state.sentConnectionHeader === false) { + if (this._removedHeader.connection) { + this._last = true; + this.shouldKeepAlive = false; + } else if (state.sentConnectionHeader === false) { var shouldSendKeepAlive = this.shouldKeepAlive && (state.sentContentLengthHeader || this.useChunkedEncodingByDefault || @@ -260,7 +271,7 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) { if (state.sentContentLengthHeader == false && state.sentTransferEncodingHeader == false) { - if (this._hasBody) { + if (this._hasBody && !this._removedHeader['transfer-encoding']) { if (this.useChunkedEncodingByDefault) { state.messageHeader += 'Transfer-Encoding: chunked\r\n'; this.chunkedEncoding = true; @@ -325,6 +336,10 @@ OutgoingMessage.prototype.setHeader = function(name, value) { this._headerNames = this._headerNames || {}; this._headers[key] = value; this._headerNames[key] = name; + + if (automaticHeaders[key]) { + this._removedHeader[key] = false; + } }; @@ -349,11 +364,17 @@ OutgoingMessage.prototype.removeHeader = function(name) { throw new Error('Can\'t remove headers after they are sent.'); } - if (!this._headers) return; - var key = name.toLowerCase(); - delete this._headers[key]; - delete this._headerNames[key]; + + if (key === 'date') + this.sendDate = false; + else if (automaticHeaders[key]) + this._removedHeader[key] = true; + + if (this._headers) { + delete this._headers[key]; + delete this._headerNames[key]; + } }; |