mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
introducing :addresses option
(This deprecates the :transport_options option) This should be given an array of peer addresses to connect to. It can be used when the destination IPs are known and you want to avoid resolving them, and when the destination is a unix socket (and the destination is a FS path)
This commit is contained in:
parent
108837e25e
commit
0fb343056d
@ -71,6 +71,8 @@ module HTTPX
|
||||
@inflight = 0
|
||||
@keep_alive_timeout = options.timeout.keep_alive_timeout
|
||||
@keep_alive_timer = nil
|
||||
|
||||
self.addresses = options.addresses if options.addresses
|
||||
end
|
||||
|
||||
# this is a semi-private method, to be used by the resolver
|
||||
@ -105,6 +107,8 @@ module HTTPX
|
||||
|
||||
return false if exhausted?
|
||||
|
||||
return false unless connection.addresses
|
||||
|
||||
!(@io.addresses & connection.addresses).empty? && @options == connection.options
|
||||
end
|
||||
|
||||
|
@ -13,7 +13,6 @@ module HTTPX
|
||||
@addresses = addresses
|
||||
@state = :idle
|
||||
@options = Options.new(options)
|
||||
@path = @options.transport_options[:path]
|
||||
@fallback_protocol = @options.fallback_protocol
|
||||
if @options.io
|
||||
@io = case @options.io
|
||||
@ -22,18 +21,22 @@ module HTTPX
|
||||
else
|
||||
@options.io
|
||||
end
|
||||
unless @io.nil?
|
||||
@keep_open = true
|
||||
@state = :connected
|
||||
raise Error, "Given IO objects do not match the request authority" unless @io
|
||||
|
||||
@path = @io.path
|
||||
@keep_open = true
|
||||
@state = :connected
|
||||
else
|
||||
if @options.transport_options
|
||||
warn ":#{__method__} is deprecated, use :addresses instead"
|
||||
@path = @options.transport_options[:path]
|
||||
else
|
||||
@path = addresses.first
|
||||
end
|
||||
end
|
||||
@io ||= build_socket
|
||||
end
|
||||
|
||||
def hostname
|
||||
@uri.host
|
||||
end
|
||||
|
||||
def connect
|
||||
return unless closed?
|
||||
|
||||
|
@ -69,6 +69,7 @@ module HTTPX
|
||||
:connection_class => Class.new(Connection),
|
||||
:transport => nil,
|
||||
:transport_options => nil,
|
||||
:addresses => nil,
|
||||
:persistent => false,
|
||||
:resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym,
|
||||
:resolver_options => { cache: true },
|
||||
@ -121,6 +122,10 @@ module HTTPX
|
||||
transport
|
||||
end
|
||||
|
||||
def_option(:addresses) do |addrs|
|
||||
Array(addrs)
|
||||
end
|
||||
|
||||
%w[
|
||||
params form json body ssl http2_settings
|
||||
request_class response_class headers_class request_body_class response_body_class connection_class
|
||||
|
@ -48,6 +48,11 @@ module HTTPX
|
||||
def transport_options=: (Hash[untyped, untyped]) -> void
|
||||
def with_transport_options: (Hash[untyped, untyped]) -> instance
|
||||
|
||||
# addresses
|
||||
attr_reader addresses: _ToAry[untyped]?
|
||||
def addresses=: (_ToAry[untyped]) -> void
|
||||
def with_addresses: (_ToAry[untyped]) -> instance
|
||||
|
||||
# params
|
||||
attr_reader params: Transcoder::urlencoded_input?
|
||||
def params=: (Transcoder::urlencoded_input) -> void
|
||||
|
@ -78,6 +78,7 @@ class OptionsTest < Minitest::Test
|
||||
:connection_class => bar.connection_class,
|
||||
:transport => nil,
|
||||
:transport_options => nil,
|
||||
:addresses => nil,
|
||||
:persistent => false,
|
||||
:resolver_class => bar.resolver_class,
|
||||
:resolver_options => bar.resolver_options,
|
||||
|
Loading…
x
Reference in New Issue
Block a user