uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.86k stars 569 forks source link

Omit the `Sec-WebSocket-Protocol` header or set `null` value #708

Closed enisdenjo closed 2 years ago

enisdenjo commented 2 years ago

/subprotocol/ Either a single value representing the subprotocol the server is ready to use or null. The value chosen MUST be derived from the client's handshake, specifically by selecting one of the values from the |Sec-WebSocket-Protocol| field that the server is willing to use for this connection (if any). If the client's handshake did not contain such a header field or if the server does not agree to any of the client's requested subprotocols, the only acceptable value is null. The absence of such a field is equivalent to the null value (meaning that if the server does not wish to agree to one of the suggested subprotocols, it MUST NOT send back a |Sec-WebSocket-Protocol| header field in its response). The empty string is not the same as the null value for these purposes and is not a legal value for this field. The ABNF for the value of this header field is (token), where the definitions of constructs and rules are as given in RFC2616.

RFC 6455: 4.2.2. Sending the Server's Opening Handshake

A proper response from the server, when presented with unsupported subprotocol(s) from the client, is to omit the Sec-WebSocket-Protocol or set its value to null, proceed with the upgrade and have the client handle the lack of an agreed subprotocol.

This doesn't seem possible currently. The implementation of HttpResponse.upgrade requires the secWebSocketProtocol argument to be a string like value.

Or I maybe missing something? Thanks!

enisdenjo commented 2 years ago

Sorry, seems like providing an empty Uint8Array instead does the trick. Thanks anyways!

ghost commented 2 years ago

Yep. Anything with length 0 will make the header disappear