diff --git a/test/web-socket-proxy-test.js b/test/web-socket-proxy-test.js index 2720616..b6cb9fa 100644 --- a/test/web-socket-proxy-test.js +++ b/test/web-socket-proxy-test.js @@ -64,7 +64,14 @@ vows.describe('node-http-proxy/websocket').addBatch({ // // Setup the web socket against our proxy // - var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf'); + var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf', { + origin: 'localhost' + }); + + ws.on('wsupgrade', function (req, res) { + require('eyes').inspect(req); + require('eyes').inspect(res.headers); + }); ws.on('open', function () { ws.send(utils.encode('from client')); @@ -91,7 +98,15 @@ vows.describe('node-http-proxy/websocket').addBatch({ // // Setup the web socket against our proxy // - var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf'); + var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf', { + origin: 'localhost' + }); + + ws.on('wsupgrade', function (req, res) { + require('eyes').inspect(req); + require('eyes').inspect(res.headers); + }); + ws.on('message', function (msg) { msg = utils.decode(msg); diff --git a/vendor/websocket.js b/vendor/websocket.js index 82c0297..b3789ea 100644 --- a/vendor/websocket.js +++ b/vendor/websocket.js @@ -523,14 +523,20 @@ var WebSocket = function(url, proto, opts) { httpClient.on('upgrade', (function() { var data = undefined; - return function(req, s, head) { + return function(res, s, head) { stream = s; + // + // Emit the `wsupgrade` event to inspect the raw + // arguments returned from the websocket request. + // + self.emit('wsupgrade', httpHeaders, res, s, head); + stream.on('data', function(d) { if (d.length <= 0) { return; } - + if (!data) { data = d; } else { @@ -614,7 +620,6 @@ var WebSocket = function(url, proto, opts) { }); var httpReq = httpClient.request(httpPath, httpHeaders); - httpReq.write(challenge, 'binary'); httpReq.end(); })();