You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently having issues with how subprotocols are handled whilst trying to create a WebSocket proxy to an upstream WebSocket server. The offending code seems to be the instantiation of the StandardWebSocket from ws here in src/modules/standards.ts.
From reading the ws source code I can see that the constructor takes an optional second argument of subprotocols. My problem lies in the fact that the subprotocol is forwarded from my client so exists in the headers under Sec-WebSocket-Protocol. Therefore the request is passed on to the upstream, but because the protocols are not correctly passed to the constructor, wserrors when the response from the upstream contains the same header value as it is considered unexpected.
There is a reasonably quick solution for this, as far as I am aware, which is to extract Sec-WebSocket-Protocol headers at the point of constructing the StandardWebSocket, for example...
I am not aware if this is a limitation of Cloudflare Workers themselves and is purely mirroring their behaviour. Any help would be appreciated. I am also willing to open a PR to potentially fix this, however I am not sure how I would go about testing it.
The text was updated successfully, but these errors were encountered:
I'm currently having issues with how subprotocols are handled whilst trying to create a WebSocket proxy to an upstream WebSocket server. The offending code seems to be the instantiation of the
StandardWebSocket
fromws
here in src/modules/standards.ts.From reading the
ws
source code I can see that the constructor takes an optional second argument of subprotocols. My problem lies in the fact that the subprotocol is forwarded from my client so exists in the headers underSec-WebSocket-Protocol
. Therefore the request is passed on to the upstream, but because the protocols are not correctly passed to the constructor,ws
errors when the response from the upstream contains the same header value as it is considered unexpected.There is a reasonably quick solution for this, as far as I am aware, which is to extract
Sec-WebSocket-Protocol
headers at the point of constructing theStandardWebSocket
, for example...I am not aware if this is a limitation of Cloudflare Workers themselves and is purely mirroring their behaviour. Any help would be appreciated. I am also willing to open a PR to potentially fix this, however I am not sure how I would go about testing it.
The text was updated successfully, but these errors were encountered: