Skip to content

Body from 'upgrade' request is not read #1310

@kristjanvalur

Description

@kristjanvalur

ASGI defines the extension websocket.http.response. This extension allows an application to send an arbitrary http response
as a connection rejection.

the websockets module, however, states: (in legacy.http.py)

    :func:`read_request` doesn't attempt to read the response body because
    WebSocket handshake responses don't have one. If the response contains a
    body, it may be read from ``stream`` after this coroutine returns.

the legacy.client.read_http_response() method again states that a body may be read from after the headers, but
the pertinent code https://github.com/aaugustin/websockets/blob/ba1ed7a65cc876ff4e0fcd4dd4711402836475e2/src/websockets/legacy/client.py#L322-L328 does not do that. The result is that the raised exception does not contain any body which may have been provided with the response.

This issue comes from this PR: encode/uvicorn#1907. uvicorn is using websockets in its unit tests and we can't verify that the received body is indeed the body which was sent.

If there is interest, I could attempt to provide a PR to rectify this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions