Skip to content

fix: keep Content-Length on HEAD and 304 responses#3621

Merged
benoitc merged 1 commit into
masterfrom
fix/asgi-preserve-content-length-on-head-and-304
May 3, 2026
Merged

fix: keep Content-Length on HEAD and 304 responses#3621
benoitc merged 1 commit into
masterfrom
fix/asgi-preserve-content-length-on-head-and-304

Conversation

@benoitc

@benoitc benoitc commented May 3, 2026

Copy link
Copy Markdown
Owner

RFC 9110 §6.4.2 forbids Content-Length only on 1xx and 204. HEAD MAY include the Content-Length the same GET would return; 304 MAY include the unconditional response's Content-Length. WSGI preserves app-supplied Content-Length on those statuses; ASGI was stripping it for any no-body response. Transfer-Encoding is still always stripped (no body → no chunked terminator).

RFC 9110 §6.4.2 forbids Content-Length only on 1xx and 204 responses.
HEAD MAY include the Content-Length the same GET would return, and 304
MAY include the Content-Length the unconditional response would carry.
WSGI preserves app-supplied Content-Length on those statuses; ASGI was
stripping it indiscriminately for any no-body response.

Split the predicate: _response_forbids_content_length() returns True
only for 1xx/204; _strip_body_framing_headers(headers, status) always
strips Transfer-Encoding (no body, no chunked terminator) and strips
Content-Length only when forbidden.
@benoitc benoitc merged commit 68843c8 into master May 3, 2026
24 checks passed
@benoitc benoitc deleted the fix/asgi-preserve-content-length-on-head-and-304 branch May 3, 2026 20:56
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