Closed ccamensuli closed 6 years ago
Can you please describe again your issue?
Example :
var exampleSocket = new WebSocket("ws://www.example.com/socketserver", "protocolOne");
If we call method WebSocketRequest.accept(acceptedProtocol, allowedOrigin, cookies) with a bad acceptedProtocol (not "protocolOne" )
The browser catch : failed: Error during WebSocket handshake: Unexpected response code: 500
In https://github.com/theturtle32/WebSocket-Node/blob/master/lib/WebSocketRequest.js :287
if (this.requestedProtocols.indexOf(acceptedProtocol) === -1) {
this.reject(500);
throw new Error('Specified protocol was not requested by the client.');
}
In WebSocketRequest.js Lot of reason code don' t respect protocol ?
I don't know when http error codes (<=500) are allowed ( during handshake , before swith protocol ...) I looked "http error code" in the RFC 6455 and I found this
In the server side you are responsible of properly matching the WebSocket sub-protocol. This has been discussed in other issues (I think).
This is replying with an HTTP 500 error (Internal Server Error) instead of proceeding with the websocket protocol upgrade (HTTP 101 Switching Protocols). And the reason for this is that your own bad code chose to accept the connection with the wrong protocol. That's your coding error, and it is, therefore, an Internal Server Error and the websocket connection cannot be established.
Further clarification.. this is not replying with an invalid websocket close code. It is replying with an HTTP status code while we are still speaking HTTP, before the protocol has been switched to WebSocket.
failed: Error during WebSocket handshake: Unexpected response code: 500
The method WebSocketRequest.accept in WebSocketRequest .js
Lot of reason code don' t respect protocol ?