-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Description
- I've searched for any related issues and avoided creating a duplicate
issue.
Description
I'm using the handleProtocols property when creating a server to force clients connecting to the server to send the name of the required protocol. But when the client doesn't send any protocol, the function is not executed so validation can't be done.
Reproducible in:
- version: 6.2.1
- Node.js version(s): v8.15.1
Steps to reproduce:
-
Create a
WebSocket.Serverwith a function in thehandleProtocolsproperty of the Options object -
Create a client connecting with the server that doesn't send the
Sec-WebSocket-Protocol. -
The connection is established without calling the handleProtocols function.
Expected result:
I expect it to be executed always to be able to reject the request if the required protocol is not sent by the client.
Actual result:
Function is not executed and the socket is established.
Attachments:
function handleProtocols(protocols: string[]) {
return protocols.includes(PROTOCOL) ? PROTOCOL : false;
}
httpServer = http.createServer();
const wss = new WebSocket.Server({
handleProtocols,
server,
});
httpServer.listen(PORT);
const ws = new WebSocket(`ws://localhost:${PORT}`);
Metadata
Metadata
Assignees
Labels
No labels