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