Skip to content

Websockets 14 does not accept Transfer-Encoding header in error responses #1550

@Jolmberg

Description

@Jolmberg

After upgrading to websockets 14, websockets.connect is raising the exception NotImplementedError: transfer codings aren't supported in a scenario that previously raised InvalidStatusCode (503). I was expecting it to change to InvalidStatus, which would have been fine, but even if I catch the NotImplementedError, there is no way to extract an error code from it. The issue arises when my server, in response to the websocket upgrade request returns a 503 error, with transfer-encoding: chunked and then a short error message in the body. While it could be argued that this particular message could just use Content-Length rather than chunked encoding, this does seem like a regression on the part of websockets.

The entire back and forth looks something like this.
Request (sent with websockets 14.1):

GET /path HTTP/1.1
Host: 192.168.0.1:8888
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: bDKBNWhBF+86IyQBcT176A==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Protocol: xyz
Authorization: Bearer 97eab12b-2766-46ca-9ec4-f65d8d26d64c
User-Agent: Python/3.12 websockets/14.1

Response:

HTTP/1.1 503 Service Unavailable
date: Fri, 15 Nov 2024 08:17:57 GMT
server: Cowboy
transfer-encoding: chunked

This did not go well

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