Commit 6e679c80 authored by indexzero's avatar indexzero

[test] Improve websocket tests to inspect outgoing and incoming HTTP headers...

[test] Improve websocket tests to inspect outgoing and incoming HTTP headers to test origin mismatch bugs
parent 360e79a0
...@@ -64,7 +64,14 @@ vows.describe('node-http-proxy/websocket').addBatch({ ...@@ -64,7 +64,14 @@ vows.describe('node-http-proxy/websocket').addBatch({
// //
// Setup the web socket against our proxy // 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.on('open', function () {
ws.send(utils.encode('from client')); ws.send(utils.encode('from client'));
...@@ -91,7 +98,15 @@ vows.describe('node-http-proxy/websocket').addBatch({ ...@@ -91,7 +98,15 @@ vows.describe('node-http-proxy/websocket').addBatch({
// //
// Setup the web socket against our proxy // 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) { ws.on('message', function (msg) {
msg = utils.decode(msg); msg = utils.decode(msg);
......
...@@ -523,9 +523,15 @@ var WebSocket = function(url, proto, opts) { ...@@ -523,9 +523,15 @@ var WebSocket = function(url, proto, opts) {
httpClient.on('upgrade', (function() { httpClient.on('upgrade', (function() {
var data = undefined; var data = undefined;
return function(req, s, head) { return function(res, s, head) {
stream = s; 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) { stream.on('data', function(d) {
if (d.length <= 0) { if (d.length <= 0) {
return; return;
...@@ -614,7 +620,6 @@ var WebSocket = function(url, proto, opts) { ...@@ -614,7 +620,6 @@ var WebSocket = function(url, proto, opts) {
}); });
var httpReq = httpClient.request(httpPath, httpHeaders); var httpReq = httpClient.request(httpPath, httpHeaders);
httpReq.write(challenge, 'binary'); httpReq.write(challenge, 'binary');
httpReq.end(); httpReq.end();
})(); })();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment