mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-06 00:02:08 -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,
|
||||
:persistent => false,
|
||||
:resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym,
|
||||
:resolver_options => { cache: true },
|
||||
}
|
||||
|
||||
defaults.merge!(options)
|
||||
|
@ -158,7 +158,7 @@ module HTTPX
|
||||
next unless connection # probably a retried query for which there's an answer
|
||||
|
||||
@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"] })
|
||||
end
|
||||
end
|
||||
|
@ -237,7 +237,7 @@ module HTTPX
|
||||
end
|
||||
else
|
||||
@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"] })
|
||||
end
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ module HTTPX
|
||||
def early_resolve(connection, hostname: connection.origin.host)
|
||||
addresses = connection.addresses ||
|
||||
ip_resolve(hostname) ||
|
||||
Resolver.cached_lookup(hostname) ||
|
||||
(@resolver_options.cache && Resolver.cached_lookup(hostname)) ||
|
||||
system_resolve(hostname)
|
||||
return unless addresses
|
||||
|
||||
|
@ -14,10 +14,13 @@ module HTTPX
|
||||
|
||||
def initialize(options)
|
||||
@options = Options.new(options)
|
||||
roptions = @options.resolver_options
|
||||
@resolver_options = Resolver::Options.new(@options.resolver_options)
|
||||
@state = :idle
|
||||
@resolver = Resolv::DNS.new(roptions.nil? ? nil : roptions)
|
||||
@resolver.timeouts = roptions[:timeouts] if roptions
|
||||
resolv_options = @resolver_options.to_h
|
||||
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
|
||||
|
||||
def closed?
|
||||
|
Loading…
x
Reference in New Issue
Block a user