-
Notifications
You must be signed in to change notification settings - Fork 52
Conform WebSocketHTTPHandler to RFC 6455 section 4.2.1 #29
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
Conversation
Previously the handler did not strictly check for all required headers, and did not verify their values.
Codecov Report
@@ Coverage Diff @@
## main #29 +/- ##
==========================================
- Coverage 99.75% 99.66% -0.09%
==========================================
Files 42 42
Lines 2002 2062 +60
==========================================
+ Hits 1997 2055 +58
- Misses 5 7 +2
Continue to review full report at Codecov.
|
I also added a test for the new checks, but it would probably be better if I split it into a test per rule (and updated it to use validateHandshakeRequestHeaders now that I've refactored through checks into their own function). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thank you for these RFC fixes.
A month ago I had no idea how websockets actually worked so this really helps 🙏🏻.
RE: the requirement for WebSockets requiring the One use case I have for FlyingFox is to assist within testing. |
And I have renamed the handler here. |
You're welcome! While reading through the RFC I also found out that I had no idea how it actually worked hahah, there's certainly a lot to learn by reading the RFC documents, but I will admit that they can be quite bland sometimes. I never knew that websocket connections started as HTTP requests and then switched, the more you know. |
I agree with that reasoning, I don't see any issues with straying from the RFC in that regard 👍 |
RFC 6455 section 4.2.1 prescribes which headers are mandatory for a WebSocket handshake request to be correct. It also details what each of these headers should contain. This PR brings
WebSocketHTTPHander
up to spec (which has a typo by the way, but I didn't change that to keep this PR focussed).I have documented the new code in a way that makes it easy to match up each check with its corresponding RFC rule (see
WebSocketHTTPHander.verifyHandshakeRequestHeaders
).There is one conundrum that I ran into while implementing the checks, which is that rule 1 mandates that websocket connections must begin as
GET
requests, however in FlyingFox the method for websocket endpoints is up to users of the framework. We could add some kind of check toappendRoute
, or we could just leave it given that developers will probably realise pretty quickly that their websocket won't work as aPOST
endpoint. Another option would be creating a separate method for hosting websocket endpoints such asappendWebSocketRoute
which takes only a path and doesn't let developers specify the method.