From da674ec4df2b371f09e912f3b376c48581090a0f Mon Sep 17 00:00:00 2001 From: Arttu Liimola Date: Sun, 30 Aug 2015 22:17:18 +0300 Subject: [PATCH] Modify the set-cookie header fix to work with node 0.10.x. --- lib/http-proxy/passes/ws-incoming.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/http-proxy/passes/ws-incoming.js b/lib/http-proxy/passes/ws-incoming.js index 1284f64..eb77adf 100644 --- a/lib/http-proxy/passes/ws-incoming.js +++ b/lib/http-proxy/passes/ws-incoming.js @@ -1,5 +1,6 @@ var http = require('http'), https = require('https'), + util = require('util'), common = require('../common'), passes = exports; @@ -113,12 +114,24 @@ var passes = exports; if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead); - socket.write('HTTP/1.1 101 Switching Protocols\r\n'); - socket.write(proxyRes.rawHeaders.map(function(v, i, a) { - return !(i % 2) ? v + ": " + a[i+1] : null; - }).filter(function (v) { - return v ? true : false; - }).join('\r\n') + '\r\n\r\n'); + var writeHead = [ + 'HTTP/1.1 101 Switching Protocols' + ]; + + Object.keys(proxyRes.headers).map(function(i) { + if (util.isArray(proxyRes.headers[i])) { + var a = proxyRes.headers[i]; + var len = a.length; + + for (var x = 0; x < len; x++) { + writeHead.push(i + ": " + a[x]); + } + } else { + writeHead.push(i + ": " + proxyRes.headers[i]); + } + }); + + socket.write(writeHead.join('\r\n') + '\r\n\r\n'); proxySocket.pipe(socket).pipe(proxySocket); server.emit('open', proxySocket);