uvicorn icon indicating copy to clipboard operation
uvicorn copied to clipboard

Add `code` on `events.CloseConnection` for `wsproto`

Open Kludex opened this issue 3 years ago • 2 comments

I'm not sure if this is the right code, but events.CloseConnection receives code as a mandatory field, so without it, you'll have an exception on missing parameters.

List of codes: https://www.iana.org/assignments/websocket/websocket.xhtml RFC: https://www.rfc-editor.org/rfc/rfc6455.html

I've noticed this issue while annotating wsproto_impl.

Kludex avatar May 10 '22 05:05 Kludex

Well spotted.

How about we use 1002 "Protocol Error"? That seems like it'd fit quite well here.

lovelydinosaur avatar May 11 '22 09:05 lovelydinosaur

The handle_no_connect() method ignores the code from the event anyway. I guess there needs to be some change there.

Kludex avatar May 13 '22 04:05 Kludex

I've replaced the logic here. :sweat_smile:

Kludex avatar Oct 29 '22 20:10 Kludex

I'm fine with this being merged. Thanks @tomchristie 🙏

As a note, wsproto_impl.py is the only file that is missing to add type annotation on uvicorn folder. I'll work on that this week.

Kludex avatar Oct 31 '22 11:10 Kludex