Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/WebSocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ WebSocketServer.prototype.handleUpgrade = function (req, socket, upgradeHead, cb
// check for wrong path
if (this.options.path) {
var u = url.parse(req.url);
if (u && u.pathname !== this.options.path) return;
if (u && u.pathname !== this.options.path) {
abortConnection(socket, 400, 'Bad Request');
return;
}
}

if (typeof req.headers.upgrade === 'undefined' || req.headers.upgrade.toLowerCase() !== 'websocket') {
Expand Down
20 changes: 20 additions & 0 deletions test/WebSocketServer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,26 @@ describe('WebSocketServer', function() {
});
});
});

it('can not finish upgrade when path is not right', function(done) {
var wss = new WebSocketServer({port: ++port, path: '/ws'}, function() {
var options = {
port: port,
host: '127.0.0.1',
headers: {
'Connection': 'Upgrade',
'Upgrade': 'websocket'
},
};
var req = http.request(options);
req.end();
req.on('response', function(res) {
res.statusCode.should.eql(400);
wss.close();
done();
});
});
});
});

describe('hybi mode', function() {
Expand Down