Skip to content

Commit 99d91c9

Browse files
Vendor net-http and net-protocol in RubyGems
1 parent c94e359 commit 99d91c9

37 files changed

+7195
-76
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ AllCops:
1010
- lib/rubygems/resolver/molinillo/**/*
1111
- lib/rubygems/tsort/**/*
1212
- lib/rubygems/optparse/**/*
13+
- lib/rubygems/net-protocol/**/*
14+
- lib/rubygems/net-http/**/*
1315
- bundler/lib/bundler/vendor/**/*
1416
CacheRootDirectory: tmp/rubocop
1517
MaxFilesInCache: 5000

Manifest.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ lib/rubygems/installer.rb
423423
lib/rubygems/installer_uninstaller_utils.rb
424424
lib/rubygems/local_remote_options.rb
425425
lib/rubygems/name_tuple.rb
426+
lib/rubygems/net-http/LICENSE.txt
427+
lib/rubygems/net-http/lib/net/http.rb
428+
lib/rubygems/net-http/lib/net/http/backward.rb
429+
lib/rubygems/net-http/lib/net/http/exceptions.rb
430+
lib/rubygems/net-http/lib/net/http/generic_request.rb
431+
lib/rubygems/net-http/lib/net/http/header.rb
432+
lib/rubygems/net-http/lib/net/http/proxy_delta.rb
433+
lib/rubygems/net-http/lib/net/http/request.rb
434+
lib/rubygems/net-http/lib/net/http/requests.rb
435+
lib/rubygems/net-http/lib/net/http/response.rb
436+
lib/rubygems/net-http/lib/net/http/responses.rb
437+
lib/rubygems/net-http/lib/net/http/status.rb
438+
lib/rubygems/net-http/lib/net/https.rb
439+
lib/rubygems/net-protocol/lib/net/protocol.rb
440+
lib/rubygems/net/http.rb
426441
lib/rubygems/openssl.rb
427442
lib/rubygems/optparse.rb
428443
lib/rubygems/optparse/.document

Rakefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,25 @@ 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+
150169
desc "Vendor a specific version of pub_grub to bundler"
151170
Automatiek::RakeTask.new("pub_grub") do |lib|
152171
lib.version = "main"

lib/rubygems/gemcutter_utilities.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def host
8484
# If +allowed_push_host+ metadata is present, then it will only allow that host.
8585

8686
def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, scope: nil, credentials: {}, &block)
87-
require "net/http"
87+
require_relative "net/http"
8888

8989
self.host = host if host
9090
unless self.host
@@ -119,7 +119,7 @@ def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, scop
119119
end
120120

121121
def mfa_unauthorized?(response)
122-
response.is_a?(Net::HTTPUnauthorized) && response.body.start_with?("You have enabled multifactor authentication")
122+
response.is_a?(Gem::Net::HTTPUnauthorized) && response.body.start_with?("You have enabled multifactor authentication")
123123
end
124124

125125
def update_scope(scope)
@@ -208,13 +208,13 @@ def verify_api_key(key)
208208

209209
def with_response(response, error_prefix = nil)
210210
case response
211-
when Net::HTTPSuccess then
211+
when Gem::Net::HTTPSuccess then
212212
if block_given?
213213
yield response
214214
else
215215
say clean_text(response.body)
216216
end
217-
when Net::HTTPPermanentRedirect, Net::HTTPRedirection then
217+
when Gem::Net::HTTPPermanentRedirect, Gem::Net::HTTPRedirection then
218218
message = "The request has redirected permanently to #{response["location"]}. Please check your defined push host URL."
219219
message = "#{error_prefix}: #{message}" if error_prefix
220220

@@ -244,7 +244,7 @@ def set_api_key(host, key)
244244
private
245245

246246
def request_with_otp(method, uri, &block)
247-
request_method = Net::HTTP.const_get method.to_s.capitalize
247+
request_method = Gem::Net::HTTP.const_get method.to_s.capitalize
248248

249249
Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req|
250250
req["OTP"] = otp if otp
@@ -297,7 +297,7 @@ def webauthn_verification_url(credentials)
297297
request.basic_auth credentials[:email], credentials[:password]
298298
end
299299
end
300-
response.is_a?(Net::HTTPSuccess) ? response.body : nil
300+
response.is_a?(Gem::Net::HTTPSuccess) ? response.body : nil
301301
end
302302

303303
def pretty_host(host)
@@ -366,6 +366,6 @@ def get_key_name(scope)
366366
end
367367

368368
def api_key_forbidden?(response)
369-
response.is_a?(Net::HTTPForbidden) && response.body.start_with?("The API key doesn't have access")
369+
response.is_a?(Gem::Net::HTTPForbidden) && response.body.start_with?("The API key doesn't have access")
370370
end
371371
end

lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
##
44
# The WebauthnListener Response class is used by the WebauthnListener to create
5-
# responses to be sent to the Gem host. It creates a Net::HTTPResponse instance
5+
# responses to be sent to the Gem host. It creates a Gem::Net::HTTPResponse instance
66
# when initialized and can be converted to the appropriate format to be sent by a socket using `to_s`.
7-
# Net::HTTPResponse instances cannot be directly sent over a socket.
7+
# Gem::Net::HTTPResponse instances cannot be directly sent over a socket.
88
#
99
# Types of response classes:
1010
# - OkResponse
@@ -60,7 +60,7 @@ def reason_phrase
6060
def body; end
6161

6262
def build_http_response
63-
response_class = Net::HTTPResponse::CODE_TO_OBJ[code.to_s]
63+
response_class = Gem::Net::HTTPResponse::CODE_TO_OBJ[code.to_s]
6464
@http_response = response_class.new("1.1", code, reason_phrase)
6565
@http_response.instance_variable_set(:@read, true)
6666

lib/rubygems/gemcutter_utilities/webauthn_poller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def poll_for_otp(webauthn_url, credentials)
4646
Timeout.timeout(TIMEOUT_IN_SECONDS) do
4747
loop do
4848
response = webauthn_verification_poll_response(webauthn_url, credentials)
49-
raise Gem::WebauthnVerificationError, response.message unless response.is_a?(Net::HTTPSuccess)
49+
raise Gem::WebauthnVerificationError, response.message unless response.is_a?(Gem::Net::HTTPSuccess)
5050

5151
require "json"
5252
parsed_response = JSON.parse(response.body)

lib/rubygems/net-http/LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions
5+
are met:
6+
1. Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
2. Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22+
SUCH DAMAGE.

0 commit comments

Comments
 (0)