python-hyper / wsproto

Sans-IO WebSocket protocol implementation
https://wsproto.readthedocs.io/
MIT License
261 stars 38 forks source link

Attempt to close with local-only codes (e.g. 1006) results in normal close (1000) #182

Open samsamoa opened 1 year ago

samsamoa commented 1 year ago

Currently, if you close a websocket with code 1006 (which is not allowed), the result is a 1000-code closure: https://github.com/python-hyper/wsproto/blob/main/src/wsproto/frame_protocol.py#L576-L577

I suspect this should instead be either a 1002 error or an exception, but I'm not certain.

This resulted in a latent bug in hypercorn (an ASGI web server that uses wsproto) where websockets were closed with code 1000 on internal server errors: https://github.com/pgjones/hypercorn/pull/112