python-websockets/websockets

Make MAX_LINE configurable

dangeReis opened this issue · 5 comments

We currently have a cookie line header of 8718 characters, which is larger than MAX_LINE setting of 8192. Can this either be bumped up to 16K, or better yet be configurable in the ENV? Also it would be nice if a proper error message was returned, we are currently getting

HTTP/1.1 400 Bad Request
Date: Thu, 06 Jun 2024 16:09:28 GMT
Content-Type: text/plain
Content-Length: 77
Connection: keep-alive

Failed to open a WebSocket connection: did not receive a valid HTTP request.

Which isn't very helpful.

https://github.com/python-websockets/websockets/blame/01195322d2620a44039b716cb93c108c2ca9b6b9/src/websockets/legacy/http.py#L14

Yea I'm facing the same issue. The cookie line is longer than MAX_LINE.
What's weird is that I configured withCredentials: false in socketio client but it still gets sent in the header. I also tried to configure fastapi middleware but the cookie wasn't found in the request. Not sure if this is an issue with websockets or socketio

The best answer I have right now is still this one: #1243 (comment)

I just made a change that gives you a slightly better error message in that case:

Failed to open a WebSocket connection: did not receive a valid HTTP request; line too long.

I'm going to make it configurable via an environment variable.

Fixed in bbb3161.

Please be aware that, if you are currently monkey-patching MAX_LINE, that will break in version 13.0. You will have to set the WEBSOCKETS_MAX_LINE_LENGTH environment variable instead.