When upgrading an HTTP connection to a websocket, one can provide one or more subprotocols in the optional HTTP header ‘Sec-WebSocket-Protocol’.
If the server accepts any of the subprotocols it responds with HTTP response code 101 (“HTTP/1.1 101 Switching Protocols”) and includes the HTTP header ‘Sec-WebSocket-Protocol’ indicating the selected subprotocol.
But how should the server correctly handle an unknown/unsupported subprotocol?
Should this be done ‘within’ the HTTP connection — by use of some HTTP response code?
Or should the connection be upgraded to a websocket — and immediately be closed by the server by sending a ‘Close Frame’ with some of the predefined websocket Status codes?
What does the RFC6455 say? I cannot come to a conclusion.
How does existing server implementations handle it?
Regards
/Per/
From a brief glimpse at RFC 6455, I believe the WebSocket Subprotocol is optional and negotiated. In section 4.2.2, under "Server Rquirements":
The server should not send a subprotocol response header with a value other than ‘null’ if it did not agree to use the subprotocol with the client, and it is the client’s responsibility to either continue or terminate the connection at that point.