Need to specify subprotocol for WebSocket connection

The server that I am working with requires the Sec-WebSocket-Protocol request header field be set to a non-standard (not registered) subprotocol in the client request to upgrade to WebSockets. No matter what I've tried, I can't seem to get that added to the header issued by a WebSocket node. Any suggestions?

1 Like

I'm having exactly the same problem. Did you ever find a solution?

To elaborate, when connecting from JavaScript, the call needs to look like this:

ws = new WebSocket("ws://myserver", ["protocolName"]);

Node-RED gets a 403 response because it can only do:

ws = new WebSocket("ws://myserver");

Hi @alphie, (and @ChipsNSalsa - my apologies for your question having gone unanswered for so long).

The WebSocket node doesn't provide any way to modify the headers of the request. There is an item on the backlog to allow it to do so, but it isn't something being looked currently.

I solved my immediate problem by installing a modified version of the WebSocket node with the protocol value I needed hard-coded. It worked great. 15 seconds to modify the code, 2 hours to get it running in parallel to the production version. From this experience, I estimate it would take about 20 minutes of work to expose this parameter to the control panel.

Very happy to consider a pull request. Thanks.

1 Like