fix(http): keep the error body of a failed streaming request by yspbwx2010 · Pull Request #12 · mcpplibs/tinyhttps
Repository navigation
fix(http): keep the error body of a failed streaming request - #12
Closed
yspbwx2010 wants to merge 1 commit into mcpplibs:master from yspbwx2010:fix/stream-error-body
Closed
fix(http): keep the error body of a failed streaming request #12 yspbwx2010 wants to merge 1 commit into mcpplibs:master from yspbwx2010:fix/stream-error-body
Conversation
yspbwx2010 commented Aug 29, 2026 · edited Loading
Copy link Copy Markdown
Contributor
Fixes #11 .
send() fills HttpResponse::body on every path including failures; send_stream()
was the one entry point that dropped it, because the whole body went into SseParser
and a non-2xx answer is an error document rather than an event stream -- no \n\n
boundary, no events, bytes stranded in the parser's private buffer.
This captures the body when the status is not 2xx:
- Additive only. Events are still parsed and dispatched exactly as before; on a
2xx stream nothing is copied and the success path is byte-identical. - Bounded.
stream_error_body_limit(1 MiB) caps the copy so a server answering
5xxwith an endless body can't grow the buffer without limit. Happy to make it a
HttpClientConfigfield instead if you'd rather it be tunable. - Tested. The truncation logic is in an exported
append_within_limit, in the
same spirit asparse_chunk_size_linefrom fix(http): reject incomplete chunked transfers #9 -- three unit tests cover under,
across and past the limit. The wiring (captureBody = !response.ok()) is covered
by a live test against httpbin's/status/418, which answers non-2xx with a body
-- exactly the shapeSseParsercannot turn into events. Commenting out the capture
line makes that one test fail witherror body was dropped, and nothing else.
All 13 tests pass locally (gcc 16.1.0, x86_64-linux-gnu).
version bumped to 0.2.10; drop that hunk if you'd rather bump on release.
fix(http): keep the error body of a failed streaming request
a31e413
send() fills HttpResponse::body on every path including failures; send_stream() was the one entry point that dropped it. A non-2xx answer to a streaming request is an error document, not an event stream: SseParser finds no event boundary in it, emits nothing, and the bytes stay in its private buffer. Callers were left with a status line and no reason. Capture the body when the status is not 2xx. Events are still parsed and dispatched exactly as before, and nothing is copied on a 2xx stream, so the success path is byte-identical. The copy is bounded by stream_error_body_limit (1 MiB) so a server answering 5xx with an endless body cannot grow the buffer without limit. Truncation lives in an exported append_within_limit, in the same spirit as parse_chunk_size_line, with three unit tests for under, across and past the limit; a live test against httpbin's /status/418 covers the wiring.yspbwx2010 force-pushed the fix/stream-error-body branch from
01e4361 to
a31e413
Compare
August 29, 2026 11:25 Sunrisepeak mentioned this pull request Aug 29, 2026 ci: name the build tool in one place, and remove a pin that resolved to 2026-05 #13 Merged Sunrisepeak closed this Aug 29, 2026 Sunrisepeak reopened this Aug 29, 2026
Sunrisepeak commented Aug 29, 2026
Copy link Copy Markdown
Member
|
Reviewed against the source and by measurement. The defect is real, the diagnosis is exact, and the fix is placed correctly. Merging this. What follows is what the review found beyond it -- three of them are being sent as a follow-up rather than asked of you, because I have no push access to your fork. The report holdsOne program, one source file, built against
The fix is in the right place
1. A declared
|
Sunrisepeak commented Aug 29, 2026
Copy link Copy Markdown
Member
|
Delivered in #14 , which carries your commit as its first commit with your authorship intact -- Closing this one rather than merging it, for a mechanical reason and not a judgement on the change: its head is on a fork I have no push access to, so the three follow-up items could not be added here. Your report was right on every point that mattered , and two of them were the difficult kind:
What the review added is in #14 and in the comment above: a declared Thank you. The issue was precisely stated, the reproduction was exact, and the two things you said you had ruled out really were ruled out -- which is rarer than it should be. |
Sunrisepeak commented Aug 29, 2026
Copy link Copy Markdown
Member
|
|