Return 500 on invalid reuse of response body - #1336
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| if body isa AbstractBody | ||
| if body_closed(body) && | ||
| _server_stream_allows_body(stream) && | ||
| stream.response.content_length != 0 |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
This review seems to concern the change you made. Did you want me revise it further?
There was a problem hiding this comment.
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>
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