Skip to content

Commit

Permalink
[test] Improve websocket tests to inspect outgoing and incoming HTTP …
Browse files Browse the repository at this point in the history
…headers to test origin mismatch bugs
  • Loading branch information
indexzero committed May 18, 2011
1 parent 360e79a commit 6e679c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 17 additions & 2 deletions test/web-socket-proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions vendor/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -614,7 +620,6 @@ var WebSocket = function(url, proto, opts) {
});

var httpReq = httpClient.request(httpPath, httpHeaders);

httpReq.write(challenge, 'binary');
httpReq.end();
})();
Expand Down

0 comments on commit 6e679c8

Please sign in to comment.