Skip to content

Return 500 on invalid reuse of response body - #1336

Merged
quinnj merged 3 commits into
JuliaWeb:masterfrom
frankier:throw-on-empty-body
Aug 6, 2026
Merged

Return 500 on invalid reuse of response body#1336
quinnj merged 3 commits into
JuliaWeb:masterfrom
frankier:throw-on-empty-body

Conversation

@frankier

@frankier frankier commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

In case a response with a consumable body is consumed, currently a 400 error will be returned. However, the error is actually from the server side, so a 500 should be returned. This is done by throwing an error when _write_response_body_to_stream is called on a closed body. Additionally, the error path is modified so that the framing headers on the response are reset.

See #1333

Co-authored by Codex

In case a response with a consumable body is consumed, currently a 400 error
will be returned. However, the error is actually from the server side, so a 500
should be returned.  This is done by throwing an error when
_write_response_body_to_stream is called on a closed body. Additionally, the
error path is modified so that the framing headers on the response are reset.
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.44%. Comparing base (cb98f26) to head (e6db58e).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1336      +/-   ##
==========================================
+ Coverage   88.20%   88.44%   +0.24%     
==========================================
  Files          30       30              
  Lines       11921    11929       +8     
==========================================
+ Hits        10515    10551      +36     
+ Misses       1406     1378      -28     

☔ 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.

Comment thread src/http_server_streams.jl Outdated
if body isa AbstractBody
if body_closed(body) &&
_server_stream_allows_body(stream) &&
stream.response.content_length != 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a closed CallbackBody with Content-Length: 0, response.content_length remains -1 until startwrite parses the header. This guard runs first and changes master’s 200 to 500. Please resolve the header length here and test this case.

[reviewed by codex & quinnj]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review seems to concern the change you made. Did you want me revise it further?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah shoot. sorry about that. took care of it.

…dies

A closed response body whose empty payload is declared only via the
Content-Length header (not the content_length field) was rejected as
invalid reuse, turning master's 200 into a 500. Fall back to parsing
the header when the field is unset.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@quinnj
quinnj merged commit e5cf7a5 into JuliaWeb:master Aug 6, 2026
8 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.

2 participants