Skip to content

Preserve explicit Content-Length on bodyless server responses - #1352

Open
fredrikekre wants to merge 1 commit into
masterfrom
fe/head-content-length
Open

Preserve explicit Content-Length on bodyless server responses#1352
fredrikekre wants to merge 1 commit into
masterfrom
fe/head-content-length

Conversation

@fredrikekre

Copy link
Copy Markdown
Member

A server handler that set a Content-Length header and then completed a
HEAD request without writing a body had the header stripped before the
response head was sent: the write-mode decision conflated "suppress the
body" with "suppress the framing headers". The same stripping applied
to 304 responses.

Keep suppressing the body, but only remove Content-Length when the
status actually forbids it (1xx/204, RFC 9110 section 8.6): a HEAD
response should carry the header fields a GET would have produced
(section 9.3.2), and a 304 may repeat the Content-Length of the
representation it revalidates (section 15.4.5). This fixes the HTTP/1
and live HTTP/2 stream paths, and write_response! (which already
handled HEAD via the content_length field but stripped an explicit
Content-Length from 304 responses).

A server handler that set a Content-Length header and then completed a
HEAD request without writing a body had the header stripped before the
response head was sent: the write-mode decision conflated "suppress the
body" with "suppress the framing headers". The same stripping applied
to 304 responses.

Keep suppressing the body, but only remove Content-Length when the
status actually forbids it (1xx/204, RFC 9110 section 8.6): a HEAD
response should carry the header fields a GET would have produced
(section 9.3.2), and a 304 may repeat the Content-Length of the
representation it revalidates (section 15.4.5). This fixes the HTTP/1
and live HTTP/2 stream paths, and write_response! (which already
handled HEAD via the content_length field but stripped an explicit
Content-Length from 304 responses).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.57%. Comparing base (bc251f0) to head (83aae95).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1352      +/-   ##
==========================================
+ Coverage   88.56%   88.57%   +0.01%     
==========================================
  Files          31       31              
  Lines       11974    11976       +2     
==========================================
+ Hits        10605    10608       +3     
+ Misses       1369     1368       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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