-
Notifications
You must be signed in to change notification settings - Fork 213
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
[possible bug] 'code' is not labeled as optional #340
Comments
I believe it was intentional that it was not optional - the WebSocket spec also says:
Thus, I would say servers should default that value to 1005 if it is not contained in the frame |
So should channels default the value to 1005, then? Or maybe Uvicorn should specify |
If I was being strict, I'd say the servers should always populate this field (so uvicorn should probably add it), but in the interests of compatibility it makes sense for channels to default it as well. I'll update the spec to clarify this, if that makes sense? |
Yep, that makes sense. Thanks! |
Alright, clarified in 5118b70 - thanks for highlighting this! |
Uvicorn team is already aware of this. 👀 There's a PR in WIP adding the code on those. 🙏 |
Great! Hopefully it matches the default 1005 value suggested here? |
Not really, and now that you've mentioned... We were actually using 1000 on some places as default, see: |
Yeah, |
I see... So on the PR: https://github.com/encode/uvicorn/pull/1441/files The first one should be 1005. Correct? |
Actually... Both on that PR should be 1005? 🤔 |
Yeah, both of those should be, since they are |
Thanks Andrew :) |
If you think there's a change in Channels to be made for this, please do propose it over there. (Thanks 😉) |
@carltongibson, sure. I figure I might as well make the proposal a PR because the change is so easy to make: django/channels#1905 |
I've created a table on encode/uvicorn#1753 about the websocket codes we should be sending back, jfyk. |
In https://asgi.readthedocs.io/en/latest/specs/www.html#disconnect-receive-event-ws it does not say code is optional, yet it says "as per websocket spec", where code is optional ("may contain"). Later on in
Close - send event
it explicitly mentions that the code there is optional. In the first link should code be optional or required?If code is optional I would be happy to submit a PR to this repo to update the docs.
This is not just a theoretical question, as we are facing a bug that may be related to this. In https://github.com/django/channels/blob/38324816c115567e198a573bc294d8345df5e8a9/channels/generic/websocket.py#L105 channels assumes that the
code
key exists, but in our case it doesn't exist and a KeyError is raised.The text was updated successfully, but these errors were encountered: