-
-
Notifications
You must be signed in to change notification settings - Fork 948
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
Default WebSocket accept message headers to an empty list #1422
Conversation
Thank you for this. I guess adding/editing the test would be valuable here so this is safe for future changes. |
I've added a test, but I'm really not sure how adequate it is to do it that way. :) Just let me know if it's not. |
My interpretation of the ASGI spec is that the server will interpret the absence of |
Yes, I agree that's what it says. Wouldn't that be a breaking change? I mean that's like the case with |
No, because we didn't release it yet. This is a feature introduced a few days ago. |
Oh that makes sense, I thought it was from the last release 😆 |
Should we also change the |
@Kludex I see your point, but I'm not really sure about it, to be honest. My humble reflection on this topic: why should an application care about how exactly the server will interpret the absence of headers - be it an empty list or anything else? Why should the spec tell us about that? I'm leaning towards thinking that this is an instruction for application developers so that server developers would know what to expect. And in accordance to that, right now Uvicorn expects headers to be something iterable. Anyway, if so, shouldn't we also remove the |
Uvicorn only expects the headers to be iterable if present.
But yeah, you have a point. Ok, I'm fine with this 👍 |
@Klavionik Thanks for fixing that. I completely forgot about that. |
I think we should pick one approach and stick with it. |
We send None when it's allowed by the ASGI spec, but yeah. I agree. We should probably adapt the |
Co-authored-by: Marcelo Trylesinski <[email protected]>
Co-authored-by: Amin Alaee <[email protected]>
I accepted all the suggestions (first time using it, hope I did it right).
Happy to help! I was actually tinkering with BlackSheep, trying to add support for WebSocket connections to it, when I discovered this. I was referencing Starlette and did the same thing with the So maybe we should consider adding some kind of check to Uvicorn? Like |
Co-authored-by: Marcelo Trylesinski <[email protected]>
Thanks @Klavionik ! 🎉 |
Recently, #1361 introduced a possibility to pass a set of extra headers into the
accept
method. If no headers are passed, the default value isNone
. This value then gets sent to the protocol server.This causes Uvicorn to raise an exception:
TypeError: NoneType object is not iterable
when using websockets andTypeError: can only concatenate list (not "NoneType") to list
when using wsproto.This PR fixes this, setting the
headers
argument to an empty list if it is not passed into the method. This is recommended by the ASGI spec (https://asgi.readthedocs.io/en/latest/specs/www.html#accept-send-event).