Skip to content

Commit 198b10c

Browse files
committed
Downgrade net-http 0.7.0 because JRuby is not working
1 parent 778426f commit 198b10c

File tree

11 files changed

+43
-163
lines changed

11 files changed

+43
-163
lines changed

lib/rubygems/vendor/net-http/lib/net/http.rb

Lines changed: 24 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class HTTPHeaderSyntaxError < StandardError; end
724724
class HTTP < Protocol
725725

726726
# :stopdoc:
727-
VERSION = "0.8.0"
727+
VERSION = "0.7.0"
728728
HTTPVersion = '1.1'
729729
begin
730730
require 'zlib'
@@ -1179,7 +1179,6 @@ def initialize(address, port = nil) # :nodoc:
11791179
@debug_output = options[:debug_output]
11801180
@response_body_encoding = options[:response_body_encoding]
11811181
@ignore_eof = options[:ignore_eof]
1182-
@tcpsocket_supports_open_timeout = nil
11831182

11841183
@proxy_from_env = false
11851184
@proxy_uri = nil
@@ -1322,9 +1321,6 @@ def response_body_encoding=(value)
13221321
# Sets the proxy password;
13231322
# see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
13241323
attr_writer :proxy_pass
1325-
1326-
# Sets wheter the proxy uses SSL;
1327-
# see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
13281324
attr_writer :proxy_use_ssl
13291325

13301326
# Returns the IP address for the connection.
@@ -1636,21 +1632,6 @@ def start # :yield: http
16361632
self
16371633
end
16381634

1639-
# Finishes the \HTTP session:
1640-
#
1641-
# http = Gem::Net::HTTP.new(hostname)
1642-
# http.start
1643-
# http.started? # => true
1644-
# http.finish # => nil
1645-
# http.started? # => false
1646-
#
1647-
# Raises IOError if not in a session.
1648-
def finish
1649-
raise IOError, 'HTTP session not yet started' unless started?
1650-
do_finish
1651-
end
1652-
1653-
# :stopdoc:
16541635
def do_start
16551636
connect
16561637
@started = true
@@ -1673,36 +1654,14 @@ def connect
16731654
end
16741655

16751656
debug "opening connection to #{conn_addr}:#{conn_port}..."
1676-
begin
1677-
s =
1678-
case @tcpsocket_supports_open_timeout
1679-
when nil, true
1680-
begin
1681-
# Use built-in timeout in TCPSocket.open if available
1682-
sock = TCPSocket.open(conn_addr, conn_port, @local_host, @local_port, open_timeout: @open_timeout)
1683-
@tcpsocket_supports_open_timeout = true
1684-
sock
1685-
rescue ArgumentError => e
1686-
raise if !(e.message.include?('unknown keyword: :open_timeout') || e.message.include?('wrong number of arguments (given 5, expected 2..4)'))
1687-
@tcpsocket_supports_open_timeout = false
1688-
1689-
# Fallback to Gem::Timeout.timeout if TCPSocket.open does not support open_timeout
1690-
Gem::Timeout.timeout(@open_timeout, Gem::Net::OpenTimeout) {
1691-
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1692-
}
1693-
end
1694-
when false
1695-
# The current Ruby is known to not support TCPSocket(open_timeout:).
1696-
# Directly fall back to Gem::Timeout.timeout to avoid performance penalty incured by rescue.
1697-
Gem::Timeout.timeout(@open_timeout, Gem::Net::OpenTimeout) {
1698-
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1699-
}
1700-
end
1701-
rescue => e
1702-
e = Gem::Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions
1703-
raise e, "Failed to open TCP connection to " +
1704-
"#{conn_addr}:#{conn_port} (#{e.message})"
1705-
end
1657+
s = Gem::Timeout.timeout(@open_timeout, Gem::Net::OpenTimeout) {
1658+
begin
1659+
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1660+
rescue => e
1661+
raise e, "Failed to open TCP connection to " +
1662+
"#{conn_addr}:#{conn_port} (#{e.message})"
1663+
end
1664+
}
17061665
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
17071666
debug "opened"
17081667
if use_ssl?
@@ -1799,6 +1758,20 @@ def on_connect
17991758
end
18001759
private :on_connect
18011760

1761+
# Finishes the \HTTP session:
1762+
#
1763+
# http = Gem::Net::HTTP.new(hostname)
1764+
# http.start
1765+
# http.started? # => true
1766+
# http.finish # => nil
1767+
# http.started? # => false
1768+
#
1769+
# Raises IOError if not in a session.
1770+
def finish
1771+
raise IOError, 'HTTP session not yet started' unless started?
1772+
do_finish
1773+
end
1774+
18021775
def do_finish
18031776
@started = false
18041777
@socket.close if @socket
@@ -1848,8 +1821,6 @@ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_use_ss
18481821
}
18491822
end
18501823

1851-
# :startdoc:
1852-
18531824
class << HTTP
18541825
# Returns true if self is a class which was created by HTTP::Proxy.
18551826
def proxy_class?
@@ -1944,7 +1915,6 @@ def proxy_pass
19441915
alias proxyport proxy_port #:nodoc: obsolete
19451916

19461917
private
1947-
# :stopdoc:
19481918

19491919
def unescape(value)
19501920
require 'cgi/escape'
@@ -1973,7 +1943,6 @@ def edit_path(path)
19731943
path
19741944
end
19751945
end
1976-
# :startdoc:
19771946

19781947
#
19791948
# HTTP operations
@@ -2428,8 +2397,6 @@ def send_entity(path, data, initheader, dest, type, &block)
24282397
res
24292398
end
24302399

2431-
# :stopdoc:
2432-
24332400
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
24342401

24352402
def transport_request(req)
@@ -2587,7 +2554,7 @@ def debug(msg)
25872554
alias_method :D, :debug
25882555
end
25892556

2590-
# for backward compatibility until Ruby 4.0
2557+
# for backward compatibility until Ruby 3.5
25912558
# https://bugs.ruby-lang.org/issues/20900
25922559
# https://github.com/bblimke/webmock/pull/1081
25932560
HTTPSession = HTTP

lib/rubygems/vendor/net-http/lib/net/http/exceptions.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Gem::Net
33
# Gem::Net::HTTP exception class.
44
# You cannot use Gem::Net::HTTPExceptions directly; instead, you must use
55
# its subclasses.
6-
module HTTPExceptions # :nodoc:
6+
module HTTPExceptions
77
def initialize(msg, res) #:nodoc:
88
super msg
99
@response = res
@@ -12,7 +12,6 @@ def initialize(msg, res) #:nodoc:
1212
alias data response #:nodoc: obsolete
1313
end
1414

15-
# :stopdoc:
1615
class HTTPError < ProtocolError
1716
include HTTPExceptions
1817
end

lib/rubygems/vendor/net-http/lib/net/http/generic_request.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ def initialize(m, reqbody, resbody, uri_or_path, initheader = nil) # :nodoc:
1919

2020
if Gem::URI === uri_or_path then
2121
raise ArgumentError, "not an HTTP Gem::URI" unless Gem::URI::HTTP === uri_or_path
22-
hostname = uri_or_path.host
22+
hostname = uri_or_path.hostname
2323
raise ArgumentError, "no host component for Gem::URI" unless (hostname && hostname.length > 0)
2424
@uri = uri_or_path.dup
25+
host = @uri.hostname.dup
26+
host << ":" << @uri.port.to_s if @uri.port != @uri.default_port
2527
@path = uri_or_path.request_uri
2628
raise ArgumentError, "no HTTP request path given" unless @path
2729
else
2830
@uri = nil
31+
host = nil
2932
raise ArgumentError, "no HTTP request path given" unless uri_or_path
3033
raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty?
3134
@path = uri_or_path.dup
@@ -48,7 +51,7 @@ def initialize(m, reqbody, resbody, uri_or_path, initheader = nil) # :nodoc:
4851
initialize_http_header initheader
4952
self['Accept'] ||= '*/*'
5053
self['User-Agent'] ||= 'Ruby'
51-
self['Host'] ||= @uri.authority if @uri
54+
self['Host'] ||= host if host
5255
@body = nil
5356
@body_stream = nil
5457
@body_data = nil
@@ -242,7 +245,7 @@ def update_uri(addr, port, ssl) # :nodoc: internal use only
242245
end
243246

244247
if host = self['host']
245-
host = Gem::URI.parse("//#{host}").host # Remove a port component from the existing Host header
248+
host.sub!(/:.*/m, '')
246249
elsif host = @uri.host
247250
else
248251
host = addr
@@ -261,8 +264,6 @@ def update_uri(addr, port, ssl) # :nodoc: internal use only
261264

262265
private
263266

264-
# :stopdoc:
265-
266267
class Chunker #:nodoc:
267268
def initialize(sock)
268269
@sock = sock

lib/rubygems/vendor/net-http/lib/net/http/header.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@
179179
# - #each_value: Passes each string field value to the block.
180180
#
181181
module Gem::Net::HTTPHeader
182-
# The maximum length of HTTP header keys.
183182
MAX_KEY_LENGTH = 1024
184-
# The maximum length of HTTP header values.
185183
MAX_FIELD_LENGTH = 65536
186184

187185
def initialize_http_header(initheader) #:nodoc:
@@ -269,7 +267,6 @@ def add_field(key, val)
269267
end
270268
end
271269

272-
# :stopdoc:
273270
private def set_field(key, val)
274271
case val
275272
when Enumerable
@@ -297,7 +294,6 @@ def add_field(key, val)
297294
ary.push val
298295
end
299296
end
300-
# :startdoc:
301297

302298
# Returns the array field value for the given +key+,
303299
# or +nil+ if there is no such field;
@@ -494,7 +490,7 @@ def each_capitalized
494490

495491
alias canonical_each each_capitalized
496492

497-
def capitalize(name) # :nodoc:
493+
def capitalize(name)
498494
name.to_s.split('-'.freeze).map {|s| s.capitalize }.join('-'.freeze)
499495
end
500496
private :capitalize
@@ -961,20 +957,20 @@ def proxy_basic_auth(account, password)
961957
@header['proxy-authorization'] = [basic_encode(account, password)]
962958
end
963959

964-
def basic_encode(account, password) # :nodoc:
960+
def basic_encode(account, password)
965961
'Basic ' + ["#{account}:#{password}"].pack('m0')
966962
end
967963
private :basic_encode
968964

969-
# Returns whether the HTTP session is to be closed.
965+
# Returns whether the HTTP session is to be closed.
970966
def connection_close?
971967
token = /(?:\A|,)\s*close\s*(?:\z|,)/i
972968
@header['connection']&.grep(token) {return true}
973969
@header['proxy-connection']&.grep(token) {return true}
974970
false
975971
end
976972

977-
# Returns whether the HTTP session is to be kept alive.
973+
# Returns whether the HTTP session is to be kept alive.
978974
def connection_keep_alive?
979975
token = /(?:\A|,)\s*keep-alive\s*(?:\z|,)/i
980976
@header['connection']&.grep(token) {return true}

0 commit comments

Comments
 (0)