|
|
@ -60,6 +60,8 @@ var parsers = new FreeList('parsers', 1000, function () { |
|
|
|
parser.onHeadersComplete = function (info) { |
|
|
|
if (parser.field && (parser.value != undefined)) { |
|
|
|
parser.incoming._addHeaderLine(parser.field, parser.value); |
|
|
|
parser.field = null; |
|
|
|
parser.value = null; |
|
|
|
} |
|
|
|
|
|
|
|
parser.incoming.httpVersionMajor = info.versionMajor; |
|
|
@ -101,6 +103,10 @@ var parsers = new FreeList('parsers', 1000, function () { |
|
|
|
}; |
|
|
|
|
|
|
|
parser.onMessageComplete = function () { |
|
|
|
this.incoming.complete = true; |
|
|
|
if (parser.field && (parser.value != undefined)) { |
|
|
|
parser.incoming._addHeaderLine(parser.field, parser.value); |
|
|
|
} |
|
|
|
if (!parser.incoming.upgrade) { |
|
|
|
// For upgraded connections, also emit this after parser.execute
|
|
|
|
parser.incoming.emit("end"); |
|
|
@ -183,7 +189,9 @@ function IncomingMessage (socket) { |
|
|
|
this.connection = socket; |
|
|
|
|
|
|
|
this.httpVersion = null; |
|
|
|
this.complete = false; |
|
|
|
this.headers = {}; |
|
|
|
this.trailers = {}; |
|
|
|
|
|
|
|
// request (server) only
|
|
|
|
this.url = ""; |
|
|
@ -223,13 +231,19 @@ IncomingMessage.prototype.resume = function () { |
|
|
|
// and drop the second. Extended header fields (those beginning with 'x-') are
|
|
|
|
// always joined.
|
|
|
|
IncomingMessage.prototype._addHeaderLine = function (field, value) { |
|
|
|
var dest; |
|
|
|
if (this.complete) { |
|
|
|
dest = this.trailers |
|
|
|
} else { |
|
|
|
dest = this.headers |
|
|
|
} |
|
|
|
switch (field) { |
|
|
|
// Array headers:
|
|
|
|
case 'set-cookie': |
|
|
|
if (field in this.headers) { |
|
|
|
this.headers[field].push(value); |
|
|
|
if (field in dest) { |
|
|
|
dest[field].push(value); |
|
|
|
} else { |
|
|
|
this.headers[field] = [value]; |
|
|
|
dest[field] = [value]; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
@ -240,10 +254,10 @@ IncomingMessage.prototype._addHeaderLine = function (field, value) { |
|
|
|
case 'accept-language': |
|
|
|
case 'connection': |
|
|
|
case 'cookie': |
|
|
|
if (field in this.headers) { |
|
|
|
this.headers[field] += ', ' + value; |
|
|
|
if (field in dest) { |
|
|
|
dest[field] += ', ' + value; |
|
|
|
} else { |
|
|
|
this.headers[field] = value; |
|
|
|
dest[field] = value; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
@ -251,14 +265,14 @@ IncomingMessage.prototype._addHeaderLine = function (field, value) { |
|
|
|
default: |
|
|
|
if (field.slice(0,2) == 'x-') { |
|
|
|
// except for x-
|
|
|
|
if (field in this.headers) { |
|
|
|
this.headers[field] += ', ' + value; |
|
|
|
if (field in dest) { |
|
|
|
dest[field] += ', ' + value; |
|
|
|
} else { |
|
|
|
this.headers[field] = value; |
|
|
|
dest[field] = value; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// drop duplicates
|
|
|
|
if (!(field in this.headers)) this.headers[field] = value; |
|
|
|
if (!(field in dest)) dest[field] = value; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|