diff --git a/lib/http.js b/lib/http.js index 2f176835163..dc7901b41bd 100755 --- a/lib/http.js +++ b/lib/http.js @@ -410,9 +410,8 @@ OutgoingMessage.prototype._storeHeader = function (firstLine, headers) { if (headers) { var keys = Object.keys(headers); var isArray = (Array.isArray(headers)); - var i, l; - for (i = 0, l = keys.length; i < l; i++) { + for (var i = 0, l = keys.length; i < l; i++) { var key = keys[i]; if (isArray) { field = headers[key][0]; @@ -423,8 +422,8 @@ OutgoingMessage.prototype._storeHeader = function (firstLine, headers) { } if (Array.isArray(value)) { - for (i = 0, l = value.length; i < l; i++) { - store(field, value[i]); + for (var j = 0; j < value.length; j++) { + store(field, value[j]); } } else { store(field, value); diff --git a/test/simple/test-http-proxy.js b/test/simple/test-http-proxy.js index b3b976976a0..58fa995e280 100644 --- a/test/simple/test-http-proxy.js +++ b/test/simple/test-http-proxy.js @@ -6,14 +6,16 @@ url = require("url"); var PROXY_PORT = common.PORT; var BACKEND_PORT = common.PORT+1; -var cookies = [ - "session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT", - "prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" -]; +var cookies = [ "session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT", + "prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" ]; + +var headers = {"content-type": "text/plain", + "set-cookie": cookies, + "hello": "world" }; var backend = http.createServer(function (req, res) { common.debug("backend request"); - res.writeHead(200, {"content-type": "text/plain", "set-cookie": cookies}); + res.writeHead(200, headers); res.write("hello world\n"); res.end(); }); @@ -24,10 +26,19 @@ var proxy = http.createServer(function (req, res) { var proxy_req = proxy_client.request(url.parse(req.url).pathname); proxy_req.end(); proxy_req.addListener('response', function(proxy_res) { + + common.debug("proxy res headers: " + JSON.stringify(proxy_res.headers)); + + assert.equal('world', proxy_res.headers['hello']); + assert.equal('text/plain', proxy_res.headers['content-type']); + assert.deepEqual(cookies, proxy_res.headers['set-cookie']); + res.writeHead(proxy_res.statusCode, proxy_res.headers); + proxy_res.addListener("data", function(chunk) { res.write(chunk); }); + proxy_res.addListener("end", function() { res.end(); common.debug("proxy res"); @@ -48,7 +59,11 @@ function startReq () { req.addListener('response', function (res) { common.debug("got res"); assert.equal(200, res.statusCode); - assert.deepEqual(cookies, res.headers["set-cookie"]); + + assert.equal('world', res.headers['hello']); + assert.equal('text/plain', res.headers['content-type']); + assert.deepEqual(cookies, res.headers['set-cookie']); + res.setEncoding("utf8"); res.addListener('data', function (chunk) { body += chunk; }); res.addListener('end', function () {