Skip to content

Commit

Permalink
fixed multiple path ws server
Browse files Browse the repository at this point in the history
  • Loading branch information
sequoiar committed May 5, 2020
1 parent 06e8908 commit 9a3f5e9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/websocketpp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class WebSocketServer extends EventEmitter {
);
} else if (options.server) {
this._server = options.server;
// cache path set
if (!this._server.wsppathes) this._server.wsppathes = new Set();
if (options.path) this._server.wsppathes.add(options.path);
}

if (this._server) {
Expand Down Expand Up @@ -135,6 +138,11 @@ class WebSocketServer extends EventEmitter {
const server = this._server;

if (server) {
// delete path
if (this.options.path && server.wsppathes) {
server.wsppathes.delete(this.options.path);
}

this._removeListeners();
this._removeListeners = this._server = null;

Expand Down Expand Up @@ -187,6 +195,19 @@ class WebSocketServer extends EventEmitter {
const version = +req.headers['sec-websocket-version'];
const extensions = {};

// check on path
if (!this.shouldHandle(req)) {
const index = req.url.indexOf('?');
const wspth = index !== -1 ? req.url.slice(0, index) : req.url;

if (this._server && this._server.wsppathes && this._server.wsppathes.has(wspth)) {
// let other ws server handle it
return;
} else {
return abortHandshake(socket, 400);
}
}

if (
req.method !== 'GET' ||
req.headers.upgrade.toLowerCase() !== 'websocket' ||
Expand Down

0 comments on commit 9a3f5e9

Please sign in to comment.