Skip to content

Spec question: websocket.disconnect doesn't support the reason field #459

Closed
@frankie567

Description

@frankie567

From the WebSocket specification, it's possible to set a "reason" when either the server or the client closes the connection: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.6

In the ASGI specification, this is well supported for the "Close - send event" (i.e. close sent by the server):

asgiref/specs/www.rst

Lines 476 to 496 in db3ff43

Close - ``send`` event
''''''''''''''''''''''
Sent by the application to tell the server to close the connection.
If this is sent before the socket is accepted, the server
must close the connection with a HTTP 403 error code
(Forbidden), and not complete the WebSocket handshake; this may present on some
browsers as a different WebSocket error code (such as 1006, Abnormal Closure).
If this is sent after the socket is accepted, the server must close the socket
with the close code passed in the message (or 1000 if none is specified).
* ``type`` (*Unicode string*) -- ``"websocket.close"``.
* ``code`` (*int*) -- The WebSocket close code, as per the WebSocket
spec. Optional; if missing defaults to ``1000``.
* ``reason`` (*Unicode string*) -- A reason given for the closure, can
be any string. Optional; if missing or ``None`` default is empty
string.

However, for the "Disconnect - receive event (i.e. close sent by the client), it is not supported; only the code can be set:

asgiref/specs/www.rst

Lines 440 to 458 in db3ff43

Disconnect - ``receive`` event
''''''''''''''''''''''''''''''
Sent to the application when either connection to the client is lost, either from
the client closing the connection, the server closing the connection, or loss of the
socket.
Once you have received this event, you should expect future calls to ``send()``
to raise an exception, as described below. However, if you have highly
concurrent code, you may find calls to ``send()`` erroring slightly before you
receive this event.
Keys:
* ``type`` (*Unicode string*) -- ``"websocket.disconnect"``
* ``code`` (*int*) -- The WebSocket close code, as per the WebSocket spec. If no code
was received in the frame from the client, the server should set this to ``1005``
(the default value in the WebSocket specification).

Is there a particular reason to omit this field for this particular event?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions