diff --git a/asgiref/typing.py b/asgiref/typing.py index 71c25ed8..368aed59 100644 --- a/asgiref/typing.py +++ b/asgiref/typing.py @@ -189,6 +189,7 @@ class WebSocketResponseBodyEvent(TypedDict): class WebSocketDisconnectEvent(TypedDict): type: Literal["websocket.disconnect"] code: int + reason: Optional[str] class WebSocketCloseEvent(TypedDict): diff --git a/specs/www.rst b/specs/www.rst index 6a9d3be3..ceebb3cc 100644 --- a/specs/www.rst +++ b/specs/www.rst @@ -2,7 +2,7 @@ HTTP & WebSocket ASGI Message Format ==================================== -**Version**: 2.4 (2024-01-16) +**Version**: 2.5 (2024-06-05) The HTTP+WebSocket ASGI sub-specification outlines how to transport HTTP/1.1, HTTP/2 and WebSocket connections within ASGI. @@ -22,6 +22,7 @@ This spec has had the following versions: * ``2.2``: Allow ``None`` in the second item of ``server`` scope value. * ``2.3``: Added the ``reason`` key to the WebSocket close event. * ``2.4``: Calling ``send()`` on a closed connection should raise an error +* ``2.5``: Added the ``reason`` key to the WebSocket disconnect event. Spec versions let you understand what the server you are using understands. If a server tells you it only supports version ``2.0`` of this spec, then @@ -457,6 +458,10 @@ Keys: was received in the frame from the client, the server should set this to ``1005`` (the default value in the WebSocket specification). +* ``reason`` (*Unicode string*) -- A reason given for the disconnect, can + be any string. Optional; if missing or ``None`` default is empty + string. + Disconnected Client - ``send`` exception ''''''''''''''''''''''''''''''''''''''''