question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSocket headers encoding problem

See original GitHub issue

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

If there is a websocket connection with a non-ascii char in header, the server will explode. The problem seems to be from here: https://github.com/encode/uvicorn/blob/9dc5a43209fe081ba3e74135189252bfddf75587/uvicorn/protocols/websockets/websockets_impl.py#L102 Also, I checked the ASGI doc and in section 2.2.5 it states:

  • These are byte strings of the exact byte sequences sent by the client/to be sent by the server. While modern HTTP standards say that headers should be ASCII, older ones did not and allowed a wider range of characters. Frameworks/applications should decode headers as they deem appropriate.

So, I think uvicorn should allow for non-ascii chars in header. It is definitely the only reason that we can’t use uvicorn in production yet.

To reproduce

Expected behavior

Doesn’t explode.

Actual behavior

Explodes with an exception.

Debugging material

Environment

  • OS / Python / Uvicorn version: just run uvicorn --version
  • The exact command you’re running uvicorn with, all flags you passed included. If you run it with gunicorn please do the same. If there is a reverse-proxy involved and you cannot reproduce without it please give the minimal config of it to reproduce.

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
tomchristiecommented, Dec 9, 2022

@lavandosovich - I’d be happy to spend a little time thinking about this if we start from really basic first principles.

Can you give an example of an HTTP response that you’d like to be able to send, that you currently can’t because of this limitation?

0reactions
Kludexcommented, Dec 9, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket - Safari 9 - Invalid UTF-8 sequence in header value
The error is Invalid UTF-8 sequence in header value . It appears that Safari is requiring certain headers to be included and in...
Read more >
WebSockets header issue - k6 community forum
Hi, I do have a problem with WebSockets. ... I am naively trying to run: ws.connect( 'wss://url', { headers: { Pragma: "no-cache", ...
Read more >
WebSocket Header Problem - Game Building Help - Construct 3
WebSocket connection to 'ws://localhost:8080/game/gameendpoint' failed: Invalid UTF-8 sequence in header value C2WebSocket_plugin.js:142.
Read more >
websockets.headers — websockets 8.0.1 documentation
Source code for websockets.headers ... A library for building WebSocket servers and clients in Python with a focus on correctness and simplicity. Quick...
Read more >
Writing WebSocket servers - Web APIs | MDN
Warning: The server may listen on any port it chooses, but if it chooses any port other than 80 or 443, it may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found