diff options
author | Peter Griess <pg@std.in> | 2010-06-21 22:53:17 +0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-06-21 23:01:50 +0400 |
commit | 51bd1b4483f60d85ee19274aab98505a0b5c9105 (patch) | |
tree | 2b357ea0e987f2e65c07c11c5f1194d35dfa5be6 /lib/http.js | |
parent | 545e10f2399dd748f6261919ed3db177d02ef008 (diff) |
Only concatenate some incoming HTTP headers.
- Concatenate 'accept', 'accept-charset', 'accept-encoding',
'accept-language', 'connection', 'cookie', and 'x-*' headers.
- For all others, drop duplicates.
Diffstat (limited to 'lib/http.js')
-rw-r--r-- | lib/http.js | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/http.js b/lib/http.js index 5f051ed96b8..e3ebf75a8b3 100644 --- a/lib/http.js +++ b/lib/http.js @@ -227,13 +227,35 @@ IncomingMessage.prototype.resume = function () { this.socket.resume(); }; +// Add the given (field, value) pair to the message +// +// Per RFC2616, section 4.2 it is acceptable to join multiple instances of the +// same header with a ', ' if the header in question supports specification of +// multiple values this way. If not, we declare the first instance the winner +// and drop the second. Extended header fields (those beginning with 'x-') are +// always joined. IncomingMessage.prototype._addHeaderLine = function (field, value) { - if (field in this.headers) { - // TODO Certain headers like 'Content-Type' should not be concatinated. - // See https://www.google.com/reader/view/?tab=my#overview-page - this.headers[field] += ", " + value; - } else { + if (!(field in this.headers)) { this.headers[field] = value; + return; + } + + // If this field already exists in the request, use duplicate-resolution + // logic from RFC2616. + switch (field) { + case 'accept': + case 'accept-charset': + case 'accept-encoding': + case 'accept-language': + case 'connection': + case 'cookie': + this.headers[field] += ', ' + value; + break; + + default: + if (field[0] !== 'x' || field[1] !== '-') break; + this.headers[field] += ', ' + value; + break; } }; |