Skip to content

Default omitted HTTP response bodies to empty bytes - #2236

Open
zhechen-cs wants to merge 1 commit into
django:mainfrom
zhechen-cs:codex/default-empty-http-response-body
Open

zhechen-cs wants to merge 1 commit into
django:mainfrom
zhechen-cs:codex/default-empty-http-response-body

Conversation

@zhechen-cs

Copy link
Copy Markdown

HttpCommunicator.get_response() raises KeyError: 'body' for an otherwise valid ASGI response that omits body. The ASGI HTTP specification makes this field optional and defaults it to b"", including on the final response event.

Apply that default when assembling the response and retain byte-type validation. Tests cover a response with no body, an omitted final body after content, an omitted intermediate body, and an explicitly supplied body.

Validation: tests/test_testing.py (12 passed); suite excluding Selenium (84 passed); flake8, black, isort and diff checks passed. The Selenium group also fails intermittently on clean upstream (one connection timeout in the full baseline run; both browser tests pass alone).

Specification: https://asgi.readthedocs.io/en/latest/specs/www.html#response-body-send-event

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.

1 participant