Skip to content

fix(client): flag HTTP responses truncated at the body cap - #414

Open
pcbeingused333 wants to merge 1 commit into
darrenburns:mainfrom
pcbeingused333:fix/http-body-cap-truncation
Open

pcbeingused333 wants to merge 1 commit into
darrenburns:mainfrom
pcbeingused333:fix/http-body-cap-truncation

Conversation

@pcbeingused333

Copy link
Copy Markdown

No issue filed: direct bug-fix PR, as CONTRIBUTING allows.

Cause. HTTP.Send reads the body with io.LimitReader(resp.Body, maxBodyBytes) and decompress does the same on the decoded stream. A body larger than 64 MiB was cut at the cap with no indication: the response came back as a plain 200 and posting run reported it as passed. The SSE and gRPC paths already report this case; plain HTTP was the only silent one.

Fix. Read maxBodyBytes+1 bytes (before and after decompression). If the cap is exceeded, keep the first maxBodyBytes bytes and set Response.StreamError to response exceeded 64.00 MB, the same mechanism SSE uses: the body is preserved, the status becomes a warning (shown as "Stream interrupted", the existing label), and posting run no longer reports the request as passed. No new fields, cap value unchanged.

Tests. New in internal/client/http_test.go: body of cap+1 bytes, gzip body whose decoded size exceeds the cap (both fail on main: StreamError empty), and a body of exactly the cap (no error).

Reproduction. Serve maxBodyBytes+1 bytes from an httptest server and call NewHTTP(...).Send; on main the response is 200 with StreamError == "".


This change was prepared with the help of an AI coding assistant (Claude) and submitted on Alex's behalf; the author has not independently reviewed or run it beyond the automated tests.

Bodies larger than maxBodyBytes were silently cut and returned as a
normal 200, so a truncated response looked successful. Read one byte
past the cap (also after decompression) and set StreamError, as the SSE
path already does, keeping the first maxBodyBytes of the body.

This branch has not been deployed

No deployments
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