fix(http): keep the error body of a failed streaming request - #12
fix(http): keep the error body of a failed streaming request#12yspbwx2010 wants to merge 1 commit into
Conversation
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.
01e4361 to
a31e413
比较
|
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
|
|
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. |
|
|
Fixes #11.
send()fillsHttpResponse::bodyon every path including failures;send_stream()was the one entry point that dropped it, because the whole body went into
SseParserand a non-2xx answer is an error document rather than an event stream — no
\n\nboundary, no events, bytes stranded in the parser's private buffer.
This captures the body when the status is not 2xx:
2xx stream nothing is copied and the success path is byte-identical.
stream_error_body_limit(1 MiB) caps the copy so a server answering5xxwith an endless body can't grow the buffer without limit. Happy to make it aHttpClientConfigfield instead if you'd rather it be tunable.append_within_limit, in thesame spirit as
parse_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 coveredby a live test against httpbin's
/status/418, which answers non-2xx with a body— exactly the shape
SseParsercannot turn into events. Commenting out the captureline makes that one test fail with
error body was dropped, and nothing else.All 13 tests pass locally (gcc 16.1.0, x86_64-linux-gnu).
versionbumped to0.2.10; drop that hunk if you'd rather bump on release.