Skip to content

Comments

Pass headers down instead of using a block#9021

Open
tenderlove wants to merge 1 commit intoruby:masterfrom
tenderlove:pass-headers
Open

Pass headers down instead of using a block#9021
tenderlove wants to merge 1 commit intoruby:masterfrom
tenderlove:pass-headers

Conversation

@tenderlove
Copy link
Member

Right now we are buffering entire gems in memory when we download them.

I would like to open the possibility of streaming assets rather than storing the entire asset in memory. In order to accomplish this, I would like to allow callers to pass a block to indicate that they "want to stream".

Before this commit, we would use the block to set headers on the request object. This commit passes the headers down to construct the request object. Callers know the headers they want to set before calling the method, so it makes sense to pass them in via parameters rather than as a block

Right now we are buffering entire gems in memory when we download them.

  * https://github.com/rubygems/rubygems/blob/66c94f65c8a05484f2d12cb0bccd8513da5c65ef/lib/rubygems/request.rb#L208-L216

I would like to open the possibility of streaming assets rather than
storing the entire asset in memory.  In order to accomplish this, I
would like to allow callers to pass a block to indicate that they "want
to stream".

Before this commit, we would use the block to set headers on
the request object.  This commit passes the headers down to construct
the request object.  Callers know the headers they want to set before
calling the method, so it makes sense to pass them in via parameters
rather than as a block
@Edouard-chin
Copy link
Contributor

I think we'll need to modify this one too

def request(*args)
super do |req|
req.delete("User-Agent") if headers["User-Agent"]
yield req if block_given?

@colby-swandale colby-swandale self-assigned this Oct 23, 2025
@colby-swandale
Copy link
Member

I believe this method will also need updating

def request_with_otp(method, uri, &block)
request_method = Gem::Net::HTTP.const_get method.to_s.capitalize
Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req|
req["OTP"] = otp if otp
block.call(req)
end
ensure
options[:otp] = nil if webauthn_enabled?
end

@hsbt
Copy link
Member

hsbt commented Feb 13, 2026

@tenderlove Can you look #9021 (comment)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants