mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00

Gem::RemoteFetcher uses Gem::Request, which adds the RubyGems UA.
Gem::RemoteFetcher is used to download gems, as well as the full index.
We would like the bundler UA to be used whenever bundler is making
requests.
This PR also avoids unsafely mutating the headers hash on the shared
`Gem::RemoteFetcher.fetcher` instance, which could cause corruption or
incorrect headers when making parallel requests. Instead, we create one
remote fetcher per rubygems remote, which is similar to the connection
segregation bundler is already doing
f0e8dacdec
25 lines
772 B
Ruby
25 lines
772 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "base"
|
|
|
|
module Bundler
|
|
class Fetcher
|
|
class Index < Base
|
|
def specs(_gem_names)
|
|
Bundler.rubygems.fetch_all_remote_specs(remote, gem_remote_fetcher)
|
|
rescue Gem::RemoteFetcher::FetchError => e
|
|
case e.message
|
|
when /certificate verify failed/
|
|
raise CertificateFailureError.new(display_uri)
|
|
when /401/
|
|
raise BadAuthenticationError, remote_uri if remote_uri.userinfo
|
|
raise AuthenticationRequiredError, remote_uri
|
|
when /403/
|
|
raise AuthenticationForbiddenError, remote_uri
|
|
else
|
|
raise HTTPError, "Could not fetch specs from #{display_uri} due to underlying error <#{e.message}>"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|