Allow Response::Body#each to take a buffer_size - #856
Open
hikmetba-bit wants to merge 1 commit into
Open
hikmetba-bit wants to merge 1 commit into
hikmetba-bit wants to merge 1 commit into
Conversation
Body#each always read in HTTP::Connection::BUFFER_SIZE (16KB) chunks with no way to override it, which meant streaming large responses (e.g. multi-gigabyte files via ActionController::Live) required many more reads than necessary. Add an optional buffer_size: keyword to #each, defaulting to the existing Connection::BUFFER_SIZE so behavior is unchanged unless a caller opts in, per the implementation @ixti sketched in httprb#782. Fixes httprb#782. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Fixes #782.
Body#eachalways read inHTTP::Connection::BUFFER_SIZE(16KB) chunks with no way to override it, which meant streaming large responses (e.g. multi-gigabyte files viaActionController::Live) required many more reads than necessary.Change
Adds an optional
buffer_size:keyword to#each, defaulting to the existingConnection::BUFFER_SIZEso behavior is unchanged unless a caller opts in — per the implementation @ixti sketched directly in the issue:(adapted slightly to the current
readpartial(*)-forwarding signature andloop/rescue EOFErrorcontrol flow already in this codebase).Also updated the RBS signature in
sig/http.rbsforResponse::Body#each.Testing
buffer_size:is forwarded to the underlyingreadpartial, one confirming the default is stillConnection::BUFFER_SIZEwhen nobuffer_size:is given.ArgumentError: wrong number of arguments/ defaultnilinstead of16384), and pass with it.test/http/response/**andbody_test.rbfiles: 502 runs, 0 failures, 0 errors.bundle exec steep check: no new type errors (only 4 pre-existing, unrelatedRedundant ignore commentwarnings in other files).bundle exec rubocopon the changed Ruby files: no offenses.🤖 Generated with Claude Code