mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-27 00:03:01 -05:00
Merge branch 'issue-206' into 'master'
Finishing Happy Eyeballs v2 Closes #206 See merge request os85/httpx!225
This commit is contained in:
commit
777b505900
2
Gemfile
2
Gemfile
@ -17,7 +17,7 @@ group :test do
|
||||
gem "minitest-proveit"
|
||||
gem "ruby-ntlm"
|
||||
gem "sentry-ruby" if RUBY_VERSION >= "2.4.0"
|
||||
gem "spy"
|
||||
gem "spy", "< 1.0.4" # TODO: remove this once upstream fixes bug
|
||||
if RUBY_VERSION < "2.3.0"
|
||||
gem "webmock", "< 3.15.0"
|
||||
else
|
||||
|
||||
@ -76,6 +76,13 @@ module HTTPX
|
||||
self.addresses = @options.addresses if @options.addresses
|
||||
end
|
||||
|
||||
def clone_new_connection
|
||||
new_conn = self.class.new(@type, @origin, @options)
|
||||
once(:open, &new_conn.method(:reset))
|
||||
new_conn.once(:open, &method(:close))
|
||||
new_conn
|
||||
end
|
||||
|
||||
# this is a semi-private method, to be used by the resolver
|
||||
# to initiate the io object.
|
||||
def addresses=(addrs)
|
||||
|
||||
@ -129,6 +129,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def on_resolver_connection(connection)
|
||||
@connections << connection unless @connections.include?(connection)
|
||||
found_connection = @connections.find do |ch|
|
||||
ch != connection && ch.mergeable?(connection)
|
||||
end
|
||||
|
||||
@ -69,7 +69,8 @@ module HTTPX
|
||||
@building_connection = true
|
||||
connection = @options.connection_class.new("ssl", @uri, @options.merge(ssl: { alpn_protocols: %w[h2] }))
|
||||
@pool.init_connection(connection, @options)
|
||||
emit_addresses(connection, @family, @uri_addresses)
|
||||
# only explicity emit addresses if connection didn't pre-resolve, i.e. it's not an IP.
|
||||
emit_addresses(connection, @family, @uri_addresses) unless connection.addresses
|
||||
@building_connection = false
|
||||
connection
|
||||
end
|
||||
|
||||
@ -63,20 +63,26 @@ module HTTPX
|
||||
log { "resolver: A response, applying resolution delay..." }
|
||||
@pool.after(0.05) do
|
||||
# double emission check
|
||||
unless connection.addresses && addresses.intersect?(connection.addresses)
|
||||
|
||||
connection.addresses = addresses
|
||||
emit(:resolve, connection)
|
||||
end
|
||||
emit_resolved_connection(connection, addresses) unless connection.addresses && addresses.intersect?(connection.addresses)
|
||||
end
|
||||
else
|
||||
connection.addresses = addresses
|
||||
emit(:resolve, connection)
|
||||
emit_resolved_connection(connection, addresses)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def emit_resolved_connection(connection, addresses)
|
||||
if connection.io && connection.connecting? && @pool
|
||||
new_connection = connection.clone_new_connection
|
||||
@pool.init_connection(new_connection, connection.options)
|
||||
connection = new_connection
|
||||
end
|
||||
connection.addresses = addresses
|
||||
|
||||
emit(:resolve, connection)
|
||||
end
|
||||
|
||||
def early_resolve(connection, hostname: connection.origin.host)
|
||||
addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname))
|
||||
|
||||
|
||||
@ -36,6 +36,8 @@ module HTTPX
|
||||
@keep_alive_timeout: Numeric?
|
||||
@total_timeout: Numeric?
|
||||
|
||||
def clone_new_connection: () -> instance
|
||||
|
||||
def addresses: () -> Array[ipaddr]?
|
||||
|
||||
def addresses=: (Array[ipaddr]) -> void
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user