mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-29 00:01:06 -05:00
options: also freeze inner unfrozen vars; fixed message of resolve
timeout to include host
This commit is contained in:
parent
f5fcc24aa6
commit
15a4fb83ba
@ -110,20 +110,18 @@ module HTTPX
|
||||
end
|
||||
|
||||
def initialize(options = {})
|
||||
defaults = DEFAULT_OPTIONS.merge(options)
|
||||
defaults.each do |k, v|
|
||||
next if v.nil?
|
||||
|
||||
begin
|
||||
value = __send__(:"option_#{k}", v)
|
||||
instance_variable_set(:"@#{k}", value)
|
||||
rescue NoMethodError
|
||||
raise Error, "unknown option: #{k}"
|
||||
end
|
||||
end
|
||||
__initialize__(options)
|
||||
freeze
|
||||
end
|
||||
|
||||
def freeze
|
||||
super
|
||||
@origin.freeze
|
||||
@timeout.freeze
|
||||
@headers.freeze
|
||||
@addresses.freeze
|
||||
end
|
||||
|
||||
def option_origin(value)
|
||||
URI(value)
|
||||
end
|
||||
@ -249,5 +247,21 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def __initialize__(options = {})
|
||||
defaults = DEFAULT_OPTIONS.merge(options)
|
||||
defaults.each do |k, v|
|
||||
next if v.nil?
|
||||
|
||||
begin
|
||||
value = __send__(:"option_#{k}", v)
|
||||
instance_variable_set(:"@#{k}", value)
|
||||
rescue NoMethodError
|
||||
raise Error, "unknown option: #{k}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -18,12 +18,6 @@ module HTTPX
|
||||
require "httpx/plugins/cookies/set_cookie_parser"
|
||||
end
|
||||
|
||||
module OptionsMethods
|
||||
def option_cookies(value)
|
||||
value.is_a?(Jar) ? value : Jar.new(value)
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
extend Forwardable
|
||||
|
||||
@ -77,7 +71,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
module OptionsMethods
|
||||
def initialize(*)
|
||||
def __initialize__(*)
|
||||
super
|
||||
|
||||
return unless @headers.key?("cookie")
|
||||
@ -89,6 +83,10 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def option_cookies(value)
|
||||
value.is_a?(Jar) ? value : Jar.new(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
register_plugin :cookies, Cookies
|
||||
|
||||
@ -117,6 +117,7 @@ module HTTPX
|
||||
|
||||
def fetch_response(request, connections, options)
|
||||
response = super
|
||||
|
||||
if response.is_a?(ErrorResponse) &&
|
||||
__proxy_error?(response) && !@_proxy_uris.empty?
|
||||
@_proxy_uris.shift
|
||||
|
||||
@ -160,7 +160,7 @@ module HTTPX
|
||||
@connections.delete(connection)
|
||||
# This loop_time passed to the exception is bogus. Ideally we would pass the total
|
||||
# resolve timeout, including from the previous retries.
|
||||
raise ResolveTimeoutError.new(loop_time, "Timed out")
|
||||
raise ResolveTimeoutError.new(loop_time, "Timed out while resolving #{host}")
|
||||
# raise NativeResolveError.new(connection, host)
|
||||
else
|
||||
log { "resolver: timeout after #{timeout}s, retry(#{@timeouts[host].first}) #{host}..." }
|
||||
|
||||
@ -117,6 +117,8 @@ module HTTPX
|
||||
REQUEST_IVARS: Array[Symbol]
|
||||
|
||||
def initialize: (?options options) -> untyped
|
||||
|
||||
def __initialize__: (?options options) -> untyped
|
||||
end
|
||||
|
||||
type options = Options | Hash[Symbol, untyped]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user