Repository navigation
fix(http_request): read the response body only up to the cap - #92
Conversation
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: none Diagnostics and supporting detailsFull summaryPull request purpose (title): fix(http_request): read the response body only up to the cap. The pull request titled `fix(http_request): read the response body only up to the cap` changes `http_request` so the response body is no longer buffered in full via `response.text()` before truncation. A new helper `read_body_capped` in `network/gate.rs` reads at most `max_response_size + 1` bytes, distinguishing "over the cap" from "exactly at the cap", and the bytes are decoded with lossy UTF-8 before going through the existing `truncate_response`. An endless or very large body now returns promptly instead of waiting for the request timeout, and memory no longer grows with every received byte. This revision reworks the regression test's server loop and result handling (hoisting the 65536-byte chunk allocation and asserting on `output.is_ok()` before unwrapping). No push-delta comparison is available. Review snapshot
Completeness: Complete Features
TestsNo supported feature-to-test mapping was produced. Test execution is not inferred. FindingsNo active actionable findings. Before mergeNone. Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Comment |
Summary
http_requestread the whole response body withresponse.text()and only then cut it tomax_response_size. A large body was buffered in full before the cap applied. A body that never ends (a stream, or a hostile server) kept the call waiting until the request timeout, and memory grew with every byte received.The body is now read in chunks with
response.chunk()and reading stops aftermax_response_size + 1bytes. The extra byte tells "over the cap" apart from "exactly at the cap". The bytes are decoded as lossy UTF-8, the same decodingtext()did since thecharsetfeature is off. The result then goes through the existing byte-safetruncate_response. The reader is a small helper innetwork/gate.rs(read_body_capped), so the other network tools can use it later.web_fetchis not changed here: it needs a decision on its download ceiling first.Related issue
None.
API or behavior changes
http_requestnow reads no more thanmax_response_size + 1bytes of a response body. The output it returns is the same as before: the body truncated to the cap, plus the existing truncation marker. An endless or very large body now returns right away and no longer waits for the request timeout.Validation
Commands actually run, with their outcome:
cargo fmt --all -- --check:rustfmt --edition 2024on the touched files only.cargo clippy --all-targets --all-features -- -D warningswas left to CI.cargo build --all-targets --all-featureswas left to CI.cargo test --all-featureswas left to CI. Only these tests ran locally:an_endless_body_is_read_only_up_to_the_capbefore the fix failed (the body read did not stop at the cap: Elapsed(())after 5 s); after the fix it passed;truncate_response_*tests passed.Tests
network/http_request_tests.rs::an_endless_body_is_read_only_up_to_the_cap: a local server sendsxbytes without stopping, against a 1000-byte cap. The response must come back within 5 s, carry the truncation marker, and hold no more than 1000 bytes of body.Documentation
Not needed:
max_response_sizeis already documented as the response-size limit.Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the description