fix: handle non-UTF-8 websocket header values

Merged
HA
5d ago
+39-2

Closes #7600.

Websocket connection setup raised UnicodeDecodeError when an ASGI request header value contained bytes that were not valid UTF-8. Decode header values as UTF-8 when possible and fall back to Latin-1 otherwise, preserving existing behavior for valid UTF-8 and avoiding a failed Socket.IO connection.

Added regression coverage for both header decoding and the EventNamespace.on_connect path, along with a bugfix news fragment.

Validation:

  • tests/units/test_app.py: 191 passed, 2 skipped
  • Ruff lint and formatting checks passed
  • git diff --check passed