Skip to content

Comments

Fix ASGI headers to use bytes instead of str#4

Merged
benoitc merged 1 commit intomainfrom
fix/asgi-headers-bytes
Feb 22, 2026
Merged

Fix ASGI headers to use bytes instead of str#4
benoitc merged 1 commit intomainfrom
fix/asgi-headers-bytes

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Feb 22, 2026

Summary

  • Fix ASGI spec compliance issue where headers were converted to Python str instead of bytes
  • The ASGI specification requires headers to be list[tuple[bytes, bytes]]
  • This was causing authentication failures and form parsing issues with Starlette/FastAPI
  • Bump version to 1.6.1

Fixes #1

The ASGI specification requires headers to be list[tuple[bytes, bytes]].
The asgi_scope_from_map() function was falling through to generic
conversion which decoded Erlang binaries as Python str instead of bytes.

This caused authentication failures and form parsing issues with
frameworks like Starlette and FastAPI, which search for headers using
bytes keys (e.g., b"content-type").

Changes:
- Add explicit header handling in asgi_scope_from_map()
- Convert header names and values using PyBytes_FromStringAndSize()
- Support both list [name, value] and tuple {name, value} formats
- Bump version to 1.6.1

Fixes #1
@benoitc benoitc merged commit 7326786 into main Feb 22, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ASGI headers presented as str instead of bytes

1 participant