mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-09 00:02:50 -04:00
passing a flag for resolvers, where you can choose to use cache or not, which is helpful for tests
This commit is contained in:
parent
992f485967
commit
60e30f3f10
@ -61,6 +61,7 @@ module HTTPX
|
|||||||
:transport_options => nil,
|
:transport_options => nil,
|
||||||
:persistent => false,
|
:persistent => false,
|
||||||
:resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym,
|
:resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym,
|
||||||
|
:resolver_options => { cache: true },
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults.merge!(options)
|
defaults.merge!(options)
|
||||||
|
@ -158,7 +158,7 @@ module HTTPX
|
|||||||
next unless connection # probably a retried query for which there's an answer
|
next unless connection # probably a retried query for which there's an answer
|
||||||
|
|
||||||
@connections.delete(connection)
|
@connections.delete(connection)
|
||||||
Resolver.cached_lookup_set(hostname, addresses)
|
Resolver.cached_lookup_set(hostname, addresses) if @resolver_options.cache
|
||||||
emit_addresses(connection, addresses.map { |addr| addr["data"] })
|
emit_addresses(connection, addresses.map { |addr| addr["data"] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -237,7 +237,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
@connections.delete(connection)
|
@connections.delete(connection)
|
||||||
Resolver.cached_lookup_set(connection.origin.host, addresses)
|
Resolver.cached_lookup_set(connection.origin.host, addresses) if @resolver_options.cache
|
||||||
emit_addresses(connection, addresses.map { |addr| addr["data"] })
|
emit_addresses(connection, addresses.map { |addr| addr["data"] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ module HTTPX
|
|||||||
def early_resolve(connection, hostname: connection.origin.host)
|
def early_resolve(connection, hostname: connection.origin.host)
|
||||||
addresses = connection.addresses ||
|
addresses = connection.addresses ||
|
||||||
ip_resolve(hostname) ||
|
ip_resolve(hostname) ||
|
||||||
Resolver.cached_lookup(hostname) ||
|
(@resolver_options.cache && Resolver.cached_lookup(hostname)) ||
|
||||||
system_resolve(hostname)
|
system_resolve(hostname)
|
||||||
return unless addresses
|
return unless addresses
|
||||||
|
|
||||||
|
@ -14,10 +14,13 @@ module HTTPX
|
|||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = Options.new(options)
|
@options = Options.new(options)
|
||||||
roptions = @options.resolver_options
|
@resolver_options = Resolver::Options.new(@options.resolver_options)
|
||||||
@state = :idle
|
@state = :idle
|
||||||
@resolver = Resolv::DNS.new(roptions.nil? ? nil : roptions)
|
resolv_options = @resolver_options.to_h
|
||||||
@resolver.timeouts = roptions[:timeouts] if roptions
|
timeouts = resolv_options.delete(:timeouts)
|
||||||
|
resolv_options.delete(:cache)
|
||||||
|
@resolver = Resolv::DNS.new(resolv_options.empty? ? nil : resolv_options)
|
||||||
|
@resolver.timeouts = timeouts if timeouts
|
||||||
end
|
end
|
||||||
|
|
||||||
def closed?
|
def closed?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user