Skip to content
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

Spec: Added reason to WebSocket Disconnect #462

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asgiref/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class WebSocketResponseBodyEvent(TypedDict):
class WebSocketDisconnectEvent(TypedDict):
type: Literal["websocket.disconnect"]
code: int
reason: Optional[str]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewgodwin Can we start using NotRequired on those?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that only appears in 3.11...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asgiref depends on typing_extensions, so it's already possible.



class WebSocketCloseEvent(TypedDict):
Expand Down
7 changes: 6 additions & 1 deletion specs/www.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a bump on the spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for me to say, but I saw it was done similarly for 2.3. Can remove it if not needed :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, any spec change should minor bump if it's backwards-compatible (like this) and a major bump if it is not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did miss out updating the main version number though - we'll need that bumped too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did miss out updating the main version number though - we'll need that bumped too.

Done 👍


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
Expand Down Expand Up @@ -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
''''''''''''''''''''''''''''''''''''''''
Expand Down
Loading