summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-12-08 12:04:13 +0000
committerBundlerbot <bot@bundler.io>2019-12-08 12:04:13 +0000
commitbada03dd6d4d15828fb5b2cf7f744948e88a69a3 (patch)
tree1500feb081d41093f8005441804755aa805abcf8 /lib/bundler
parent25595896eb0f8dfd004d941093bf1d8f4a39aeeb (diff)
parent98a91379b6e44d53d24cd3611cc4e8a1eaf4766d (diff)
downloadbundler-bada03dd6d4d15828fb5b2cf7f744948e88a69a3.tar.gz
Merge #7473
7473: Cleanup some unnecessary code r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was #7460 is very big so I want to extract these changes to a separate PR, so that we're more aware of them. ### What was your diagnosis of the problem? My diagnosis was that this code can be removed. In particular, in the `GemRemoteFetcher` class there was the following comment https://github.com/bundler/bundler/blob/25595896eb0f8dfd004d941093bf1d8f4a39aeeb/lib/bundler/gem_remote_fetcher.rb#L9-L10 After having a look, I think the comment would make sense if where it says "gemstash", it actually meant "bundler". That would make sense to me since this is about fetching remote specs, so I would assume it's the client side running it. Assuming this is the correct interpretation, we can remove the code since our minimum supported rubygems version is 2.5.2, and this code was included in rubygems in 2.5.0. ### What is your fix for the problem, implemented in this PR? My fix is to remove the `GemRemoteFetcher` class, plus simplify other related code. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/gem_remote_fetcher.rb43
-rw-r--r--lib/bundler/rubygems_integration.rb18
2 files changed, 5 insertions, 56 deletions
diff --git a/lib/bundler/gem_remote_fetcher.rb b/lib/bundler/gem_remote_fetcher.rb
deleted file mode 100644
index 9577535d63..0000000000
--- a/lib/bundler/gem_remote_fetcher.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# frozen_string_literal: true
-
-require "rubygems/remote_fetcher"
-
-module Bundler
- # Adds support for setting custom HTTP headers when fetching gems from the
- # server.
- #
- # TODO: Get rid of this when and if gemstash only supports RubyGems versions
- # that contain https://github.com/rubygems/rubygems/commit/3db265cc20b2f813.
- class GemRemoteFetcher < Gem::RemoteFetcher
- attr_accessor :headers
-
- # Extracted from RubyGems 2.4.
- def fetch_http(uri, last_modified = nil, head = false, depth = 0)
- fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
- # beginning of change
- response = request uri, fetch_type, last_modified do |req|
- headers.each {|k, v| req.add_field(k, v) } if headers
- end
- # end of change
-
- case response
- when Net::HTTPOK, Net::HTTPNotModified then
- response.uri = uri if response.respond_to? :uri
- head ? response : response.body
- when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther,
- Net::HTTPTemporaryRedirect then
- raise FetchError.new("too many redirects", uri) if depth > 10
-
- location = URI.parse response["Location"]
-
- if https?(uri) && !https?(location)
- raise FetchError.new("redirecting to non-https resource: #{location}", uri)
- end
-
- fetch_http(location, last_modified, head, depth + 1)
- else
- raise FetchError.new("bad response #{response.message} #{response.code}", uri)
- end
- end
- end
-end
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 9b23a5c4c8..3ca1831dee 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -247,12 +247,6 @@ module Bundler
EXT_LOCK
end
- def fetch_prerelease_specs
- fetch_specs(false, true)
- rescue Gem::RemoteFetcher::FetchError
- {} # if we can't download them, there aren't any
- end
-
def with_build_args(args)
ext_lock.synchronize do
old_args = build_args
@@ -502,8 +496,8 @@ module Bundler
end
end
- def fetch_specs(source, remote, name)
- path = source + "#{name}.#{Gem.marshal_version}.gz"
+ def fetch_specs(remote, name)
+ path = remote.uri.to_s + "#{name}.#{Gem.marshal_version}.gz"
fetcher = gem_remote_fetcher
fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
string = fetcher.fetch_path(path)
@@ -514,10 +508,8 @@ module Bundler
end
def fetch_all_remote_specs(remote)
- source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s)
-
- specs = fetch_specs(source, remote, "specs")
- pres = fetch_specs(source, remote, "prerelease_specs") || []
+ specs = fetch_specs(remote, "specs")
+ pres = fetch_specs(remote, "prerelease_specs") || []
specs.concat(pres)
end
@@ -535,7 +527,7 @@ module Bundler
require "resolv"
proxy = configuration[:http_proxy]
dns = Resolv::DNS.new
- Bundler::GemRemoteFetcher.new(proxy, dns)
+ Gem::RemoteFetcher.new(proxy, dns)
end
def gem_from_path(path, policy = nil)