Skip to content

Commit 57d458c

Browse files
Merge pull request #6793 from rubygems/vendor-net-http-and-net-protocol
Vendor `net-http`, `net-protocol`, `resolv`, and `timeout` to reduce conflicts between Gemfile gems and internal dependencies
2 parents 4ec37c4 + 2662e45 commit 57d458c

File tree

70 files changed

+10565
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+10565
-235
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
check-filenames=
33
check-hidden=
44
ignore-words=.codespellignore
5-
skip=*.pem,.git,man,vcr_cassettes,vendor
5+
skip=*.pem,.git,man,vcr_cassettes,vendor,net-http

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ AllCops:
99
- bundler/tmp/**/*
1010
- lib/rubygems/resolver/molinillo/**/*
1111
- lib/rubygems/tsort/**/*
12+
- lib/rubygems/timeout/**/*
13+
- lib/rubygems/resolv/**/*
1214
- lib/rubygems/optparse/**/*
15+
- lib/rubygems/net-protocol/**/*
16+
- lib/rubygems/net-http/**/*
1317
- bundler/lib/bundler/vendor/**/*
1418
CacheRootDirectory: tmp/rubocop
1519
MaxFilesInCache: 5000

Manifest.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,11 @@ bundler/lib/bundler/vendor/uri/lib/uri/version.rb
333333
bundler/lib/bundler/vendor/uri/lib/uri/ws.rb
334334
bundler/lib/bundler/vendor/uri/lib/uri/wss.rb
335335
bundler/lib/bundler/vendored_fileutils.rb
336+
bundler/lib/bundler/vendored_net_http.rb
336337
bundler/lib/bundler/vendored_persistent.rb
337338
bundler/lib/bundler/vendored_pub_grub.rb
338339
bundler/lib/bundler/vendored_thor.rb
340+
bundler/lib/bundler/vendored_timeout.rb
339341
bundler/lib/bundler/vendored_tsort.rb
340342
bundler/lib/bundler/vendored_uri.rb
341343
bundler/lib/bundler/version.rb
@@ -423,6 +425,21 @@ lib/rubygems/installer.rb
423425
lib/rubygems/installer_uninstaller_utils.rb
424426
lib/rubygems/local_remote_options.rb
425427
lib/rubygems/name_tuple.rb
428+
lib/rubygems/net-http/LICENSE.txt
429+
lib/rubygems/net-http/lib/net/http.rb
430+
lib/rubygems/net-http/lib/net/http/backward.rb
431+
lib/rubygems/net-http/lib/net/http/exceptions.rb
432+
lib/rubygems/net-http/lib/net/http/generic_request.rb
433+
lib/rubygems/net-http/lib/net/http/header.rb
434+
lib/rubygems/net-http/lib/net/http/proxy_delta.rb
435+
lib/rubygems/net-http/lib/net/http/request.rb
436+
lib/rubygems/net-http/lib/net/http/requests.rb
437+
lib/rubygems/net-http/lib/net/http/response.rb
438+
lib/rubygems/net-http/lib/net/http/responses.rb
439+
lib/rubygems/net-http/lib/net/http/status.rb
440+
lib/rubygems/net-http/lib/net/https.rb
441+
lib/rubygems/net-protocol/lib/net/protocol.rb
442+
lib/rubygems/net/http.rb
426443
lib/rubygems/openssl.rb
427444
lib/rubygems/optparse.rb
428445
lib/rubygems/optparse/.document
@@ -463,6 +480,7 @@ lib/rubygems/request_set/lockfile.rb
463480
lib/rubygems/request_set/lockfile/parser.rb
464481
lib/rubygems/request_set/lockfile/tokenizer.rb
465482
lib/rubygems/requirement.rb
483+
lib/rubygems/resolv/lib/resolv.rb
466484
lib/rubygems/resolver.rb
467485
lib/rubygems/resolver/activation_request.rb
468486
lib/rubygems/resolver/api_set.rb
@@ -543,6 +561,8 @@ lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA.pem
543561
lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem
544562
lib/rubygems/stub_specification.rb
545563
lib/rubygems/text.rb
564+
lib/rubygems/timeout.rb
565+
lib/rubygems/timeout/lib/timeout.rb
546566
lib/rubygems/tsort.rb
547567
lib/rubygems/tsort/.document
548568
lib/rubygems/tsort/LICENSE.txt

Rakefile

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,13 @@ if File.exist?("tool/automatiek.rake")
189189

190190
# We currently include the following changes over the official version:
191191
# * Avoid requiring the optional `net-http-pipeline` dependency, so that its version can be selected by end users.
192+
# * Require vendored net/http version RubyGems if available, otherwise the stdlib version.
192193
desc "Vendor a specific version of net-http-persistent to bundler"
193194
Automatiek::RakeTask.new("net-http-persistent") do |lib|
194195
lib.version = "v4.0.2"
195196
lib.download = { github: "https://github.com/drbrain/net-http-persistent" }
196197
lib.namespace = "Net::HTTP::Persistent"
197-
lib.prefix = "Bundler::Persistent"
198+
lib.prefix = "Gem"
198199
lib.vendor_lib = "bundler/lib/bundler/vendor/net-http-persistent"
199200
lib.license_path = "README.rdoc"
200201

@@ -205,6 +206,15 @@ if File.exist?("tool/automatiek.rake")
205206
sublib.prefix = "Bundler"
206207
sublib.vendor_lib = "bundler/lib/bundler/vendor/connection_pool"
207208
sublib.license_path = "LICENSE"
209+
210+
sublib.dependency("timeout") do |subsublib|
211+
subsublib.version = "v0.4.1"
212+
subsublib.download = { github: "https://github.com/ruby/timeout" }
213+
subsublib.namespace = "Timeout"
214+
subsublib.prefix = "Gem"
215+
subsublib.vendor_lib = "lib/rubygems/timeout"
216+
subsublib.license_path = "License.txt"
217+
end
208218
end
209219

210220
lib.dependency("uri") do |sublib|
@@ -215,6 +225,60 @@ if File.exist?("tool/automatiek.rake")
215225
sublib.vendor_lib = "bundler/lib/bundler/vendor/uri"
216226
sublib.license_path = "LICENSE.txt"
217227
end
228+
229+
lib.dependency("net-http") do |sublib|
230+
sublib.version = "v0.4.0"
231+
sublib.download = { github: "https://github.com/ruby/net-http" }
232+
sublib.namespace = "Net"
233+
sublib.prefix = "Gem"
234+
sublib.vendor_lib = "lib/rubygems/net-http"
235+
sublib.license_path = "LICENSE.txt"
236+
237+
sublib.dependency("net-protocol") do |subsublib|
238+
subsublib.version = "v0.2.2"
239+
subsublib.download = { github: "https://github.com/ruby/net-protocol" }
240+
subsublib.namespace = "Net"
241+
subsublib.prefix = "Gem"
242+
subsublib.vendor_lib = "lib/rubygems/net-protocol"
243+
subsublib.license_path = "License.txt"
244+
245+
subsublib.dependency("timeout") do |ssslib|
246+
ssslib.version = "v0.4.1"
247+
ssslib.download = { github: "https://github.com/ruby/timeout" }
248+
ssslib.namespace = "Timeout"
249+
ssslib.prefix = "Gem"
250+
ssslib.vendor_lib = "lib/rubygems/timeout"
251+
ssslib.license_path = "License.txt"
252+
end
253+
end
254+
255+
sublib.dependency("timeout") do |subsublib|
256+
subsublib.version = "v0.4.1"
257+
subsublib.download = { github: "https://github.com/ruby/timeout" }
258+
subsublib.namespace = "Timeout"
259+
subsublib.prefix = "Gem"
260+
subsublib.vendor_lib = "lib/rubygems/timeout"
261+
subsublib.license_path = "License.txt"
262+
end
263+
264+
sublib.dependency("resolv") do |subsublib|
265+
subsublib.version = "v0.2.2"
266+
subsublib.download = { github: "https://github.com/ruby/resolv" }
267+
subsublib.namespace = "Resolv"
268+
subsublib.prefix = "Gem"
269+
subsublib.vendor_lib = "lib/rubygems/resolv"
270+
subsublib.license_path = "License.txt"
271+
272+
subsublib.dependency("timeout") do |ssslib|
273+
ssslib.version = "v0.4.1"
274+
ssslib.download = { github: "https://github.com/ruby/timeout" }
275+
ssslib.namespace = "Timeout"
276+
ssslib.prefix = "Gem"
277+
ssslib.vendor_lib = "lib/rubygems/timeout"
278+
ssslib.license_path = "License.txt"
279+
end
280+
end
281+
end
218282
end
219283
end
220284

bundler/lib/bundler/compact_index_client/updater.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def append(remote_path, local_path, etag_path)
3333
# Subtract a byte to ensure the range won't be empty.
3434
# Avoids 416 (Range Not Satisfiable) responses.
3535
response = @fetcher.call(remote_path, request_headers(etag, file.size - 1))
36-
break true if response.is_a?(Net::HTTPNotModified)
36+
break true if response.is_a?(Gem::Net::HTTPNotModified)
3737

3838
file.digests = parse_digests(response)
3939
# server may ignore Range and return the full response
40-
if response.is_a?(Net::HTTPPartialContent)
40+
if response.is_a?(Gem::Net::HTTPPartialContent)
4141
break false unless file.append(response.body.byteslice(1..-1))
4242
else
4343
file.write(response.body)
@@ -51,7 +51,7 @@ def append(remote_path, local_path, etag_path)
5151
def replace(remote_path, local_path, etag_path)
5252
etag = etag_path.read.tap(&:chomp!) if etag_path.file?
5353
response = @fetcher.call(remote_path, request_headers(etag))
54-
return true if response.is_a?(Net::HTTPNotModified)
54+
return true if response.is_a?(Gem::Net::HTTPNotModified)
5555
CacheFile.write(local_path, response.body, parse_digests(response))
5656
CacheFile.write(etag_path, etag(response))
5757
end

bundler/lib/bundler/fetcher.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# frozen_string_literal: true
22

33
require_relative "vendored_persistent"
4+
require_relative "vendored_timeout"
45
require "cgi"
56
require "securerandom"
67
require "zlib"
7-
require "rubygems/request"
88

99
module Bundler
1010
# Handles all the fetching with the rubygems server
@@ -83,7 +83,7 @@ def initialize(remote_uri)
8383
FAIL_ERRORS = begin
8484
fail_errors = [AuthenticationRequiredError, BadAuthenticationError, AuthenticationForbiddenError, FallbackError, SecurityError]
8585
fail_errors << Gem::Requirement::BadRequirementError
86-
fail_errors.concat(NET_ERRORS.map {|e| Net.const_get(e) })
86+
fail_errors.concat(NET_ERRORS.map {|e| Gem::Net.const_get(e) })
8787
end.freeze
8888

8989
class << self
@@ -253,7 +253,7 @@ def connection
253253
Bundler.settings[:ssl_client_cert]
254254
raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)
255255

256-
con = PersistentHTTP.new name: "bundler", proxy: :ENV
256+
con = Gem::Net::HTTP::Persistent.new name: "bundler", proxy: :ENV
257257
if gem_proxy = Gem.configuration[:http_proxy]
258258
con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy
259259
end
@@ -288,10 +288,10 @@ def gemspec_cached_path(spec_file_name)
288288
end
289289

290290
HTTP_ERRORS = [
291-
Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH,
291+
Gem::Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH,
292292
Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN,
293-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
294-
PersistentHTTP::Error, Zlib::BufError, Errno::EHOSTUNREACH
293+
Gem::Net::HTTPBadResponse, Gem::Net::HTTPHeaderSyntaxError, Gem::Net::ProtocolError,
294+
Gem::Net::HTTP::Persistent::Error, Zlib::BufError, Errno::EHOSTUNREACH
295295
].freeze
296296

297297
def bundler_cert_store
@@ -307,6 +307,7 @@ def bundler_cert_store
307307
end
308308
else
309309
store.set_default_paths
310+
require "rubygems/request"
310311
Gem::Request.get_cert_files.each {|c| store.add_file c }
311312
end
312313
store

bundler/lib/bundler/fetcher/compact_index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def call(path, headers)
121121
rescue NetworkDownError => e
122122
raise unless Bundler.feature_flag.allow_offline_install? && headers["If-None-Match"]
123123
ui.warn "Using the cached data for the new index because of a network error: #{e}"
124-
Net::HTTPNotModified.new(nil, nil, nil)
124+
Gem::Net::HTTPNotModified.new(nil, nil, nil)
125125
end
126126
end
127127
end

bundler/lib/bundler/fetcher/downloader.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,35 @@ def fetch(uri, headers = {}, counter = 0)
2020
Bundler.ui.debug("HTTP #{response.code} #{response.message} #{filtered_uri}")
2121

2222
case response
23-
when Net::HTTPSuccess, Net::HTTPNotModified
23+
when Gem::Net::HTTPSuccess, Gem::Net::HTTPNotModified
2424
response
25-
when Net::HTTPRedirection
25+
when Gem::Net::HTTPRedirection
2626
new_uri = Bundler::URI.parse(response["location"])
2727
if new_uri.host == uri.host
2828
new_uri.user = uri.user
2929
new_uri.password = uri.password
3030
end
3131
fetch(new_uri, headers, counter + 1)
32-
when Net::HTTPRequestedRangeNotSatisfiable
32+
when Gem::Net::HTTPRequestedRangeNotSatisfiable
3333
new_headers = headers.dup
3434
new_headers.delete("Range")
3535
new_headers["Accept-Encoding"] = "gzip"
3636
fetch(uri, new_headers)
37-
when Net::HTTPRequestEntityTooLarge
37+
when Gem::Net::HTTPRequestEntityTooLarge
3838
raise FallbackError, response.body
39-
when Net::HTTPTooManyRequests
39+
when Gem::Net::HTTPTooManyRequests
4040
raise TooManyRequestsError, response.body
41-
when Net::HTTPUnauthorized
41+
when Gem::Net::HTTPUnauthorized
4242
raise BadAuthenticationError, uri.host if uri.userinfo
4343
raise AuthenticationRequiredError, uri.host
44-
when Net::HTTPForbidden
44+
when Gem::Net::HTTPForbidden
4545
raise AuthenticationForbiddenError, uri.host
46-
when Net::HTTPNotFound
47-
raise FallbackError, "Net::HTTPNotFound: #{filtered_uri}"
46+
when Gem::Net::HTTPNotFound
47+
raise FallbackError, "Gem::Net::HTTPNotFound: #{filtered_uri}"
4848
else
49-
raise HTTPError, "#{response.class}#{": #{response.body}" unless response.body.empty?}"
49+
message = "Gem::#{response.class.name.gsub(/\AGem::/, "")}"
50+
message += ": #{response.body}" unless response.body.empty?
51+
raise HTTPError, message
5052
end
5153
end
5254

@@ -56,7 +58,7 @@ def request(uri, headers)
5658
filtered_uri = URICredentialsFilter.credential_filtered_uri(uri)
5759

5860
Bundler.ui.debug "HTTP GET #{filtered_uri}"
59-
req = Net::HTTP::Get.new uri.request_uri, headers
61+
req = Gem::Net::HTTP::Get.new uri.request_uri, headers
6062
if uri.user
6163
user = CGI.unescape(uri.user)
6264
password = uri.password ? CGI.unescape(uri.password) : nil

bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
require "timeout"
1+
require_relative "../../../vendored_timeout"
22
require_relative "connection_pool/version"
33

44
class Bundler::ConnectionPool
55
class Error < ::RuntimeError; end
66

77
class PoolShuttingDownError < ::Bundler::ConnectionPool::Error; end
88

9-
class TimeoutError < ::Timeout::Error; end
9+
class TimeoutError < ::Gem::Timeout::Error; end
1010
end
1111

1212
# Generic connection pool class for sharing a limited number of objects or network connections

0 commit comments

Comments
 (0)