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?

2 Likes

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

The work on this change has been done back in Oct 2018, but has stalled in the approval process. https://github.com/node-red/node-red/pull/1938 What can be done to get his approved?

It looks like we provided a bunch of feedback and the contributor may, or may not have acted on it - without a comment from them on its current state its hard to know.

If someone wanted to check it out and report back, that would certainly help move things along. It looks like it'll need rebasing on the latest code and some merge conflicts sorting out as well.

Hi Alphie, could you give more steps on how-to hard-code? Thx.

Hi,

I also have the same problem! I tested in Firecamp websocket. I need to specify the protocol in "config" tab to get connected to the server.

Node-Red Websocket node does not have a field currently for me to enter this protocol name.

Is there any temporary solution now. Or in the future?

really look forward to have this option! THANKS.

Tom

Hi everyone - is there any way to sponsor this issue/PR? I need this feature for my use-case, and I'd be happy to put some $ toward the work required to get it rebased/reviewed and merged