mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 05:55:46 +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
17 lines
441 B
Ruby
17 lines
441 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "helpers/endpoint"
|
|
|
|
class EndpointMirrorSource < Endpoint
|
|
get "/gems/:id" do
|
|
if request.env["HTTP_X_GEMFILE_SOURCE"] == "https://server.example.org/" && request.env["HTTP_USER_AGENT"].start_with?("bundler")
|
|
File.binread("#{gem_repo1}/gems/#{params[:id]}")
|
|
else
|
|
halt 500
|
|
end
|
|
end
|
|
end
|
|
|
|
require_relative "helpers/artifice"
|
|
|
|
Artifice.activate_with(EndpointMirrorSource)
|