http: fix bailout for writeHead

Reported-by: Jackson Tian <shyvo1987@gmail.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
Alex Kocharin 2014-08-14 18:54:44 +04:00 committed by Trevor Norris
parent 9134a3bf41
commit b9960eefc2

View File

@ -172,21 +172,20 @@ ServerResponse.prototype._implicitHeader = function() {
this.writeHead(this.statusCode); this.writeHead(this.statusCode);
}; };
ServerResponse.prototype.writeHead = function(statusCode) { ServerResponse.prototype.writeHead = function(statusCode, reason, obj) {
var headers, headerIndex; var headers;
if (util.isString(arguments[1])) { if (util.isString(reason)) {
this.statusMessage = arguments[1]; // writeHead(statusCode, reasonPhrase[, headers])
headerIndex = 2; this.statusMessage = reason;
} else { } else {
// writeHead(statusCode[, headers])
this.statusMessage = this.statusMessage =
this.statusMessage || STATUS_CODES[statusCode] || 'unknown'; this.statusMessage || STATUS_CODES[statusCode] || 'unknown';
headerIndex = 1; obj = reason;
} }
this.statusCode = statusCode; this.statusCode = statusCode;
var obj = arguments[headerIndex];
if (this._headers) { if (this._headers) {
// Slow-case: when progressive API and header fields are passed. // Slow-case: when progressive API and header fields are passed.
if (obj) { if (obj) {