-
Notifications
You must be signed in to change notification settings - Fork 4
custom close codes #3
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
|
And maybe we should define some of the 3000 close codes, they're registered so they're defined here: https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number Lmk, I could make a separate PR for it (or maybe add it in this one for only one version bump :) |
|
@rawhat Could you take a look, please? :) |
|
Hmm... I wonder if I made a mistake just having this as a public type. I'm not super fond of the "fall back to normal error code" behavior... I wonder if it'd make more sense to make this opaque and have functions for the different types? Then the one for a custom code could return a |
|
That seems sensible. Do you think this warrants a |
|
I'm kind of leaning towards just public functions in the |
|
Oh yeah, that would be cool. I think the |
|
Btw, switching to a draft since it isn't production-ready really anymore |
Makes sense to me :) |
|
@rawhat One more thing. We discussed closing the connection ourselves with custom functions, but what about receiving close codes? I assume we should make the Perhaps an opaque type |
|
Hmm... currently I don't think the So technically right now, I don't think that's a concern. But if it's something that needs to be supported at some point (which seems likely?), that is definitely worth thinking about. I guess if it's documented that it falls back to Difficult one 😬 |
|
Hi there, sorry for the ghosting, had a few difficult days. |
|
No rush :) I'm also making a number of changes in here, hopefully I don't step on your toes too much. https://github.com/mtrudel/bandit/blob/619e53610370a9d2d16f95d5f82f7f4b0ec7fc7f/lib/bandit/websocket/connection.ex#L122 seems like bandit handles the automatic fallback as well, so maybe we should just do that? Sorry for the confusion 😬 |
This PR adds support for custom close codes. As defined in RFC 6455, APIs have the ability to specify their own close codes - in the 3000 range if registered with IANA, and in the 4000 if not registered.
The user of the library will have to parse these close reasons themselves in regards to their API's documentation.
In order to prevent integer overflow (we only have 2 bytes to work with), if a close code over 5000 is used or received, it will be treated like a 1000 close code. (Let me know if this should be changed, it was between this and NotProvided)