Skip to content

Commit 0d758e8

Browse files
Use vendored net-http in Bundler
1 parent 99d91c9 commit 0d758e8

File tree

21 files changed

+152
-145
lines changed

21 files changed

+152
-145
lines changed

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ 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

Rakefile

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,6 @@ if File.exist?("tool/automatiek.rake")
147147
lib.license_path = "COPYING"
148148
end
149149

150-
desc "Vendor a specific version of net-http"
151-
Automatiek::RakeTask.new("net-http") do |lib|
152-
lib.version = "v0.4.0"
153-
lib.download = { github: "https://github.com/ruby/net-http" }
154-
lib.namespace = "Net"
155-
lib.prefix = "Gem"
156-
lib.vendor_lib = "lib/rubygems/net-http"
157-
lib.license_path = "LICENSE.txt"
158-
159-
lib.dependency("net-protocol") do |sublib|
160-
sublib.version = "v0.2.2"
161-
sublib.download = { github: "https://github.com/ruby/net-protocol" }
162-
sublib.namespace = "Net"
163-
sublib.prefix = "Gem"
164-
sublib.vendor_lib = "lib/rubygems/net-protocol"
165-
sublib.license_path = "License.txt"
166-
end
167-
end
168-
169150
desc "Vendor a specific version of pub_grub to bundler"
170151
Automatiek::RakeTask.new("pub_grub") do |lib|
171152
lib.version = "main"
@@ -208,12 +189,13 @@ if File.exist?("tool/automatiek.rake")
208189

209190
# We currently include the following changes over the official version:
210191
# * 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.
211193
desc "Vendor a specific version of net-http-persistent to bundler"
212194
Automatiek::RakeTask.new("net-http-persistent") do |lib|
213195
lib.version = "v4.0.2"
214196
lib.download = { github: "https://github.com/drbrain/net-http-persistent" }
215197
lib.namespace = "Net::HTTP::Persistent"
216-
lib.prefix = "Bundler::Persistent"
198+
lib.prefix = "Gem"
217199
lib.vendor_lib = "bundler/lib/bundler/vendor/net-http-persistent"
218200
lib.license_path = "README.rdoc"
219201

@@ -234,6 +216,24 @@ if File.exist?("tool/automatiek.rake")
234216
sublib.vendor_lib = "bundler/lib/bundler/vendor/uri"
235217
sublib.license_path = "LICENSE.txt"
236218
end
219+
220+
lib.dependency("net-http") do |sublib|
221+
sublib.version = "v0.4.0"
222+
sublib.download = { github: "https://github.com/ruby/net-http" }
223+
sublib.namespace = "Net"
224+
sublib.prefix = "Gem"
225+
sublib.vendor_lib = "lib/rubygems/net-http"
226+
sublib.license_path = "LICENSE.txt"
227+
228+
sublib.dependency("net-protocol") do |subsublib|
229+
subsublib.version = "v0.2.2"
230+
subsublib.download = { github: "https://github.com/ruby/net-protocol" }
231+
subsublib.namespace = "Net"
232+
subsublib.prefix = "Gem"
233+
subsublib.vendor_lib = "lib/rubygems/net-protocol"
234+
subsublib.license_path = "License.txt"
235+
end
236+
end
237237
end
238238
end
239239

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def initialize(remote_uri)
8282
FAIL_ERRORS = begin
8383
fail_errors = [AuthenticationRequiredError, BadAuthenticationError, AuthenticationForbiddenError, FallbackError, SecurityError]
8484
fail_errors << Gem::Requirement::BadRequirementError
85-
fail_errors.concat(NET_ERRORS.map {|e| Net.const_get(e) })
85+
fail_errors.concat(NET_ERRORS.map {|e| Gem::Net.const_get(e) })
8686
end.freeze
8787

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

255-
con = PersistentHTTP.new name: "bundler", proxy: :ENV
255+
con = Gem::Net::HTTP::Persistent.new name: "bundler", proxy: :ENV
256256
if gem_proxy = Gem.configuration[:http_proxy]
257257
con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy
258258
end
@@ -289,8 +289,8 @@ def gemspec_cached_path(spec_file_name)
289289
HTTP_ERRORS = [
290290
Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH,
291291
Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN,
292-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
293-
PersistentHTTP::Error, Zlib::BufError, Errno::EHOSTUNREACH
292+
Gem::Net::HTTPBadResponse, Gem::Net::HTTPHeaderSyntaxError, Gem::Net::ProtocolError,
293+
Gem::Net::HTTP::Persistent::Error, Zlib::BufError, Errno::EHOSTUNREACH
294294
].freeze
295295

296296
def bundler_cert_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

0 commit comments

Comments
 (0)