Add bounded chunked responses to httpcore - #220
Open
Bronek wants to merge 2 commits into
Open
Conversation
Bronek
force-pushed
the
bronek/sse_httpcore
branch
from
September 7, 2026 14:53
33f4067 to
9c4b6b2
Compare
Bronek
marked this pull request as ready for review
September 7, 2026 15:49
Move the unsent response head and read buffer from ServerConnection into ChunkedResponse. Append one HTTP chunk per nonempty push and reuse the read buffer as discard scratch. Refuse pushes whose framed output would take pending bytes past 64 KiB. Track time without committed writes using caller-supplied instants; clear the wait when output drains. The caller owns connection closure. No terminal chunk is emitted. Add frame_chunked_head for a 200 response with caller-selected content headers, chunked transfer encoding, and Connection: close. Tests cover head ordering, chunk framing, push rejection, partial drains, capacity reuse for repeated bursts, waiting-clock transitions, discarded input, and moving both buffers without copying. Production wiring, SSE channels, /eth/v1/events, and the ADR-0004 amendment remain for the next change. Assisted-by: Claude Code:claude-fable-5-1 Assisted-by: Codex:gpt-6-astra
Reserve the 64 KiB output allowance when constructing ChunkedResponse and trim excess capacity inherited from the response buffer. Accepted pushes then reuse that allocation through partial and full drains. Reduce the inherited read buffer to 4 KiB of discard scratch, releasing capacity that request handling may have grown toward 16 MiB. Assert that the initial response head is nonempty and fits the output allowance. Resizing at the transition may reallocate either buffer; the swap no longer promises no copying. The output limit includes the response head and chunk framing, while discard scratch is separate. Tests cover output capacity across partial drains, allocation reuse after repeated bursts and a maximum-sized push, scratch reduction after a large request body, and rejection of an oversized head. Assisted-by: Claude Code:claude-fable-5-1 Assisted-by: Codex:gpt-6-astra
Bronek
force-pushed
the
bronek/sse_httpcore
branch
from
September 8, 2026 08:49
9c4b6b2 to
05035f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ServerConnectionframes response bodies withContent-Length. Server-sent events need a response that stays open as more data arrives. This PR addsChunkedResponseto support that lifetime, with HTTP chunked framing and bounded buffers.ServerConnection::into_streamtransfers the queued response head and buffers intoChunkedResponse. The head is sent before any appended chunks. Buffered pipelined requests are abandoned, and subsequent input is discarded. The connection cannot be reused, and closes without a terminal chunk.The transition reserves a 64 KiB send buffer and trims the inherited read buffer to 4 KiB of discard scratch. Accepted pushes do not reallocate. The unsent-byte limit includes the response head and chunk framing; a push exceeding it is refused, requiring the caller to close the connection.
The machine also tracks time without write progress while output is pending. The caller supplies both the clock and deadline, and decides when to close a stalled connection. This measures writes accepted by the socket, not reads by the peer.
Direct machine tests cover framing, partial writes, buffer limits and allocation stability, stall timing, and the transition from request parsing to discarding input.
The stacked PR adds the first consumer: block subscriptions at
/eth/v1/events. Topic selection, event publication, and connection expiry policy belong there.