From b9960eefc2093ea639353171189652b7cf116326 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 14 Aug 2014 18:54:44 +0400 Subject: [PATCH] http: fix bailout for writeHead Reported-by: Jackson Tian Reviewed-by: Trevor Norris --- lib/_http_server.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index bcb014129f..83cab6908f 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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) {