Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocols fallback when undefined #20

Merged
merged 2 commits into from
Nov 13, 2018
Merged

protocols fallback when undefined #20

merged 2 commits into from
Nov 13, 2018

Conversation

gfaugere
Copy link
Contributor

@gfaugere gfaugere commented Mar 28, 2018

On the latest Firefox and Edge versions, with the current version of sockette.js, the usage of opts.protocols without any check causes the browser to send undefined in the Sec-WebSocket-Protocol header.

Protocol being the string undefined, the server is likely to send a 426: No Sec-WebSocket-Protocols requested supported (except if you specify on your server side that 'undefined' is a possible protocol value).

Passing [] to the WebSocket constructor instead of undefined nullify the need for protocol check on the server side, as browsers stop sending the header.

On the latest Firefox and Edge versions, with the current version of sockette.js, the usage of opts.protocols without any check causes the browser to send "undefined" in the Sec-WebSocket-Protocol header.

Protocol being undefined, the server is likely to send a 426: No Sec-WebSocket-Protocols requested supported (except if you specify on your server side that 'undefined' is a possible protocol value).

Passing [] to the WebSocket constructor instead of undefined nullify the need for protocol check on the server side, as browsers stop sending the header.
Copy link
Owner

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, thanks~!

I feel like this is a browser bug to be honest. Or, at least, it's very easy to check on the server side:

req.headers['Sec-WebSocket-Protocol'] !== void 0
// vs
'Sec-WebSocket-Protocol' in req.headers

I'll revisit this tomorrow when I'm not so tired. Thanks again 😄

@mattia85
Copy link

Hello @lukeed,
i'm getting this problem on Firefox yet, could you please accept and merge the pull request from @Inva0?

Thank you.

@lukeed
Copy link
Owner

lukeed commented Nov 13, 2018

I forgot all about this 🙈 Thanks!

After some research & poking at Mozilla, no progress. This is a Mozilla bug, but we need to patch it on our end since if/when the fix comes, it ofc wouldn't apply to users on existing browsers.

Sorry for the delay, but the fix is much appreciated. Thank you!

@lukeed lukeed merged commit a465457 into lukeed:master Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants