Class: HTTPX::Options
- Inherits:
-
Object
- Object
- HTTPX::Options
- Defined in:
- lib/httpx/options.rb,
sig/options.rbs
Overview
Contains a set of options which are passed and shared across from session to its requests or responses.
Defined Under Namespace
Modules: OptionMethodsCache Classes: Timeouts
Constant Summary collapse
- BUFFER_SIZE =
1 << 14
- WINDOW_SIZE =
16K
1 << 14
- MAX_BODY_THRESHOLD_SIZE =
112K
(1 << 10) * 112
- KEEP_ALIVE_TIMEOUT =
20- PING_TIMEOUT =
2- SETTINGS_TIMEOUT =
10- CLOSE_HANDSHAKE_TIMEOUT =
10- CONNECT_TIMEOUT =
READ_TIMEOUT = WRITE_TIMEOUT = 60
- RESOLVER_TYPES =
%i[memory file].freeze
- USER_AGENT =
default value used for "user-agent" header, when not overridden.
"httpx.rb/#{VERSION}".freeze
- REQUEST_BODY_IVARS =
%i[headers].freeze
- RESOLVER_IVARS =
%i[ @resolver_class @resolver_cache @resolver_options @resolver_native_class @resolver_system_class @resolver_https_class ].freeze
- SET_TEMPORARY_NAME =
rubocop:disable Lint/UselessConstantScoping these really need to be defined at the end of the class
->(klass, pl = nil) do if klass.respond_to?(:set_temporary_name) # ruby 3.4 only name = klass.name || "#{klass.superclass.name}(plugin)" name = "#{name}/#{pl}" if pl klass.set_temporary_name(name) end end
- DEFAULT_OPTIONS =
{ :max_requests => Float::INFINITY, :debug => nil, :debug_level => (ENV["HTTPX_DEBUG"] || 1).to_i, :debug_redact => ENV.key?("HTTPX_DEBUG_REDACT"), :ssl => EMPTY_HASH, :http2_settings => { settings_enable_push: 0 }.freeze, :fallback_protocol => "http/1.1", :supported_compression_formats => %w[gzip deflate], :decompress_response_body => true, :compress_request_body => true, :max_response_headers => 1000, :max_response_header_value_size => nil, :max_response_body_size => Float::INFINITY, :timeout => Timeouts.new, :headers_class => Class.new(Headers, &SET_TEMPORARY_NAME), :headers => EMPTY_HASH, :window_size => WINDOW_SIZE, :buffer_size => BUFFER_SIZE, :body_threshold_size => MAX_BODY_THRESHOLD_SIZE, :request_class => Class.new(Request, &SET_TEMPORARY_NAME), :response_class => Class.new(Response, &SET_TEMPORARY_NAME), :request_body_class => Class.new(Request::Body, &SET_TEMPORARY_NAME), :response_body_class => Class.new(Response::Body, &SET_TEMPORARY_NAME), :pool_class => Class.new(Pool, &SET_TEMPORARY_NAME), :connection_class => Class.new(Connection, &SET_TEMPORARY_NAME), :http1_class => Class.new(Connection::HTTP1, &SET_TEMPORARY_NAME), :http2_class => Class.new(Connection::HTTP2, &SET_TEMPORARY_NAME), :resolver_native_class => Class.new(Resolver::Native, &SET_TEMPORARY_NAME), :resolver_system_class => Class.new(Resolver::System, &SET_TEMPORARY_NAME), :resolver_https_class => Class.new(Resolver::HTTPS, &SET_TEMPORARY_NAME), :options_class => Class.new(self, &SET_TEMPORARY_NAME), :transport => nil, :addresses => nil, :persistent => false, :resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym, :resolver_cache => (ENV["HTTPX_RESOLVER_CACHE"] || :memory).to_sym, :resolver_options => { cache: true }.freeze, :pool_options => EMPTY_HASH, :ip_families => nil, :close_on_fork => false, }.each_value(&:freeze).freeze
- READ_TIMEOUT =
- WRITE_TIMEOUT =
Class Attribute Summary collapse
-
.options_names ⇒ Set[Symbol]
readonly
Returns the value of attribute options_names.
Instance Attribute Summary collapse
-
#addresses ⇒ Hash[String, Array[Resolver::Entry]], ...
readonly
addresses.
-
#base_path ⇒ String?
readonly
base_path.
-
#body_threshold_size ⇒ Integer
readonly
body_threshold_size.
-
#buffer_size ⇒ Integer
readonly
buffer_size.
-
#close_on_fork ⇒ Boolean
readonly
close_on_fork.
-
#compress_request_body ⇒ Boolean
readonly
compress_request_body.
-
#connection_class ⇒ singleton(Connection)
readonly
Returns the value of attribute connection_class.
-
#debug ⇒ _IOLogger?
readonly
debug.
-
#debug_level ⇒ Integer
readonly
debug_level.
-
#decompress_response_body ⇒ Boolean
readonly
decompress_response_body.
-
#fallback_protocol ⇒ String
readonly
fallback_protocol.
-
#headers ⇒ headers
readonly
headers.
-
#headers_class ⇒ singleton(Headers)
readonly
Returns the value of attribute headers_class.
-
#http1_class ⇒ singleton(Connection::HTTP1)
readonly
Returns the value of attribute http1_class.
-
#http2_class ⇒ singleton(Connection::HTTP2)
readonly
Returns the value of attribute http2_class.
-
#http2_settings ⇒ Hash[Symbol, Integer | bool]
readonly
http2_settings.
-
#io ⇒ io_option?
readonly
Returns the value of attribute io.
-
#ip_families ⇒ Array[ip_family]?
readonly
ip_families.
-
#max_concurrent_requests ⇒ maybe_unbounded?
readonly
max_concurrent_requests.
-
#max_requests ⇒ maybe_unbounded?
readonly
max_requests.
-
#max_response_body_size ⇒ maybe_unbounded
readonly
max_response_body_size.
-
#max_response_header_value_size ⇒ maybe_unbounded?
readonly
max_response_header_value_size.
-
#max_response_headers ⇒ Integer
readonly
max_response_headers.
-
#options_class ⇒ singleton(Options)
readonly
Returns the value of attribute options_class.
-
#origin ⇒ URI::Generic?
readonly
origin.
-
#persistent ⇒ Boolean
readonly
persistent.
-
#pool_class ⇒ singleton(Pool)
readonly
Returns the value of attribute pool_class.
-
#pool_options ⇒ pool_options
readonly
resolver_options.
-
#request_body_class ⇒ singleton(Request::Body)
readonly
Returns the value of attribute request_body_class.
-
#request_class ⇒ singleton(Request)
readonly
Returns the value of attribute request_class.
-
#resolver_https_class ⇒ singleton(Resolver::HTTPS)
readonly
Returns the value of attribute resolver_https_class.
-
#resolver_native_class ⇒ singleton(Resolver::Native)
readonly
classes.
-
#resolver_options ⇒ Hash[Symbol, untyped]
readonly
resolver_options.
-
#resolver_system_class ⇒ singleton(Resolver::System)
readonly
Returns the value of attribute resolver_system_class.
-
#response_body_class ⇒ singleton(Response::Body)
readonly
Returns the value of attribute response_body_class.
-
#response_class ⇒ singleton(Response)
readonly
Returns the value of attribute response_class.
-
#ssl ⇒ Hash[Symbol, untyped]
readonly
Returns the value of attribute ssl.
-
#supported_compression_formats ⇒ Array[String]
readonly
supported_compression_formats.
-
#timeout ⇒ Timeouts
readonly
timeout.
-
#transport ⇒ io_type?
readonly
transport.
-
#uri ⇒ URI?
readonly
headers.
-
#window_size ⇒ Integer
readonly
window_size.
Class Method Summary collapse
- .freeze ⇒ Object
- .inherited(klass) ⇒ Object
- .method_added(meth) ⇒ Object
- .new(options = {}) ⇒ instance
Instance Method Summary collapse
- #== ⇒ Boolean
-
#connection_options_match?(other, ignore_ivars = nil) ⇒ Boolean
checks whether
othermatches the same connection-level options. - #extend_with_plugin_classes(pl) ⇒ void
- #freeze ⇒ Object
-
#merge(other) ⇒ instance, self
returns a HTTPX::Options instance resulting of the merging of
otherwith self. - #resolver_cache ⇒ Object & Resolver::_Cache
-
#resolver_class ⇒ singleton(Resolver::Resolver)
returns the class with which to instantiate the DNS resolver.
-
#resolver_options_match?(other) ⇒ Boolean
checks whether
othermatches the same resolver-level options. - #to_hash ⇒ Hash[Symbol, untyped]
Class Attribute Details
.options_names ⇒ Set[Symbol] (readonly)
Returns the value of attribute options_names.
22 23 24 |
# File 'lib/httpx/options.rb', line 22 def @options_names end |
Instance Attribute Details
#addresses ⇒ Hash[String, Array[Resolver::Entry]], ... (readonly)
addresses
73 74 75 |
# File 'sig/options.rbs', line 73 def addresses @addresses end |
#base_path ⇒ String? (readonly)
base_path
88 89 90 |
# File 'sig/options.rbs', line 88 def base_path @base_path end |
#body_threshold_size ⇒ Integer (readonly)
body_threshold_size
58 59 60 |
# File 'sig/options.rbs', line 58 def body_threshold_size @body_threshold_size end |
#buffer_size ⇒ Integer (readonly)
buffer_size
55 56 57 |
# File 'sig/options.rbs', line 55 def buffer_size @buffer_size end |
#close_on_fork ⇒ Boolean (readonly)
close_on_fork
138 139 140 |
# File 'sig/options.rbs', line 138 def close_on_fork @close_on_fork end |
#compress_request_body ⇒ Boolean (readonly)
compress_request_body
79 80 81 |
# File 'sig/options.rbs', line 79 def compress_request_body @compress_request_body end |
#connection_class ⇒ singleton(Connection) (readonly)
Returns the value of attribute connection_class.
101 102 103 |
# File 'sig/options.rbs', line 101 def connection_class @connection_class end |
#debug ⇒ _IOLogger? (readonly)
debug
129 130 131 |
# File 'sig/options.rbs', line 129 def debug @debug end |
#debug_level ⇒ Integer (readonly)
debug_level
132 133 134 |
# File 'sig/options.rbs', line 132 def debug_level @debug_level end |
#decompress_response_body ⇒ Boolean (readonly)
decompress_response_body
82 83 84 |
# File 'sig/options.rbs', line 82 def decompress_response_body @decompress_response_body end |
#fallback_protocol ⇒ String (readonly)
fallback_protocol
126 127 128 |
# File 'sig/options.rbs', line 126 def fallback_protocol @fallback_protocol end |
#headers ⇒ headers (readonly)
headers
37 38 39 |
# File 'sig/options.rbs', line 37 def headers @headers end |
#headers_class ⇒ singleton(Headers) (readonly)
Returns the value of attribute headers_class.
109 110 111 |
# File 'sig/options.rbs', line 109 def headers_class @headers_class end |
#http1_class ⇒ singleton(Connection::HTTP1) (readonly)
Returns the value of attribute http1_class.
97 98 99 |
# File 'sig/options.rbs', line 97 def http1_class @http1_class end |
#http2_class ⇒ singleton(Connection::HTTP2) (readonly)
Returns the value of attribute http2_class.
99 100 101 |
# File 'sig/options.rbs', line 99 def http2_class @http2_class end |
#http2_settings ⇒ Hash[Symbol, Integer | bool] (readonly)
http2_settings
43 44 45 |
# File 'sig/options.rbs', line 43 def http2_settings @http2_settings end |
#io ⇒ io_option? (readonly)
Returns the value of attribute io.
123 124 125 |
# File 'sig/options.rbs', line 123 def io @io end |
#ip_families ⇒ Array[ip_family]? (readonly)
ip_families
147 148 149 |
# File 'sig/options.rbs', line 147 def ip_families @ip_families end |
#max_concurrent_requests ⇒ maybe_unbounded? (readonly)
max_concurrent_requests
46 47 48 |
# File 'sig/options.rbs', line 46 def max_concurrent_requests @max_concurrent_requests end |
#max_requests ⇒ maybe_unbounded? (readonly)
max_requests
49 50 51 |
# File 'sig/options.rbs', line 49 def max_requests @max_requests end |
#max_response_body_size ⇒ maybe_unbounded (readonly)
max_response_body_size
67 68 69 |
# File 'sig/options.rbs', line 67 def max_response_body_size @max_response_body_size end |
#max_response_header_value_size ⇒ maybe_unbounded? (readonly)
max_response_header_value_size
64 65 66 |
# File 'sig/options.rbs', line 64 def max_response_header_value_size @max_response_header_value_size end |
#max_response_headers ⇒ Integer (readonly)
max_response_headers
61 62 63 |
# File 'sig/options.rbs', line 61 def max_response_headers @max_response_headers end |
#options_class ⇒ singleton(Options) (readonly)
Returns the value of attribute options_class.
115 116 117 |
# File 'sig/options.rbs', line 115 def @options_class end |
#origin ⇒ URI::Generic? (readonly)
origin
85 86 87 |
# File 'sig/options.rbs', line 85 def origin @origin end |
#persistent ⇒ Boolean (readonly)
persistent
135 136 137 |
# File 'sig/options.rbs', line 135 def persistent @persistent end |
#pool_class ⇒ singleton(Pool) (readonly)
Returns the value of attribute pool_class.
103 104 105 |
# File 'sig/options.rbs', line 103 def pool_class @pool_class end |
#pool_options ⇒ pool_options (readonly)
resolver_options
144 145 146 |
# File 'sig/options.rbs', line 144 def @pool_options end |
#request_body_class ⇒ singleton(Request::Body) (readonly)
Returns the value of attribute request_body_class.
111 112 113 |
# File 'sig/options.rbs', line 111 def request_body_class @request_body_class end |
#request_class ⇒ singleton(Request) (readonly)
Returns the value of attribute request_class.
105 106 107 |
# File 'sig/options.rbs', line 105 def request_class @request_class end |
#resolver_https_class ⇒ singleton(Resolver::HTTPS) (readonly)
Returns the value of attribute resolver_https_class.
95 96 97 |
# File 'sig/options.rbs', line 95 def resolver_https_class @resolver_https_class end |
#resolver_native_class ⇒ singleton(Resolver::Native) (readonly)
classes
91 92 93 |
# File 'sig/options.rbs', line 91 def resolver_native_class @resolver_native_class end |
#resolver_options ⇒ Hash[Symbol, untyped] (readonly)
resolver_options
141 142 143 |
# File 'sig/options.rbs', line 141 def @resolver_options end |
#resolver_system_class ⇒ singleton(Resolver::System) (readonly)
Returns the value of attribute resolver_system_class.
93 94 95 |
# File 'sig/options.rbs', line 93 def resolver_system_class @resolver_system_class end |
#response_body_class ⇒ singleton(Response::Body) (readonly)
Returns the value of attribute response_body_class.
113 114 115 |
# File 'sig/options.rbs', line 113 def response_body_class @response_body_class end |
#response_class ⇒ singleton(Response) (readonly)
Returns the value of attribute response_class.
107 108 109 |
# File 'sig/options.rbs', line 107 def response_class @response_class end |
#ssl ⇒ Hash[Symbol, untyped] (readonly)
Returns the value of attribute ssl.
117 118 119 |
# File 'sig/options.rbs', line 117 def ssl @ssl end |
#supported_compression_formats ⇒ Array[String] (readonly)
supported_compression_formats
76 77 78 |
# File 'sig/options.rbs', line 76 def supported_compression_formats @supported_compression_formats end |
#timeout ⇒ Timeouts (readonly)
timeout
40 41 42 |
# File 'sig/options.rbs', line 40 def timeout @timeout end |
#transport ⇒ io_type? (readonly)
transport
70 71 72 |
# File 'sig/options.rbs', line 70 def transport @transport end |
#uri ⇒ URI? (readonly)
headers
34 35 36 |
# File 'sig/options.rbs', line 34 def uri @uri end |
#window_size ⇒ Integer (readonly)
window_size
52 53 54 |
# File 'sig/options.rbs', line 52 def window_size @window_size end |
Class Method Details
.freeze ⇒ Object
37 38 39 40 |
# File 'lib/httpx/options.rb', line 37 def freeze @options_names.freeze super end |
.inherited(klass) ⇒ Object
24 25 26 27 |
# File 'lib/httpx/options.rb', line 24 def inherited(klass) super klass.instance_variable_set(:@options_names, @options_names.dup) end |
.method_added(meth) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/httpx/options.rb', line 42 def method_added(meth) super return unless meth =~ /^option_(.+)$/ optname = Regexp.last_match(1) #: String if optname =~ /^(.+[^_])_+with/ # ignore alias method chain generated methods. # this is the case with RBS runtime tests. # it relies on the "_with/_without" separator, which is the most used convention, # however it shouldn't be used in practice in httpx given the plugin architecture # as the main extension API. orig_name = Regexp.last_match(1) #: String return if @options_names.include?(orig_name.to_sym) end optname = optname.to_sym attr_reader(optname) unless method_defined?(optname) @options_names << optname unless @options_names.include?(optname) end |
.new(options = {}) ⇒ instance
29 30 31 32 33 34 35 |
# File 'lib/httpx/options.rb', line 29 def new( = {}) # let enhanced options go through return if self == Options && .class < self return if .is_a?(self) super end |
Instance Method Details
#== ⇒ Boolean
155 |
# File 'sig/options.rbs', line 155
def ==: (Options other) -> bool
|
#connection_options_match?(other, ignore_ivars = nil) ⇒ Boolean
checks whether other matches the same connection-level options
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/httpx/options.rb', line 211 def (other, ignore_ivars = nil) return true if self == other # headers and other request options do not play a role, as they are # relevant only for the request. ivars = self.class..reject { |iv| REQUEST_BODY_IVARS.include?(iv) } ivars = ivars.reject { |iv| ignore_ivars.include?(iv) } if ignore_ivars other_ivars = other.class..reject { |iv| REQUEST_BODY_IVARS.include?(iv) } other_ivars = other_ivars.reject { |iv| ignore_ivars.include?(iv) } if ignore_ivars return false if ivars.size != other_ivars.size return false if ivars != other_ivars ivars.all? do |ivar| send(ivar) == other.send(ivar) end end |
#extend_with_plugin_classes(pl) ⇒ void
This method returns an undefined value.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/httpx/options.rb', line 310 def extend_with_plugin_classes(pl) # extend request class if defined?(pl::RequestMethods) || defined?(pl::RequestClassMethods) @request_class = @request_class.dup SET_TEMPORARY_NAME[@request_class, pl] @request_class.__send__(:include, pl::RequestMethods) if defined?(pl::RequestMethods) @request_class.extend(pl::RequestClassMethods) if defined?(pl::RequestClassMethods) end # extend response class if defined?(pl::ResponseMethods) || defined?(pl::ResponseClassMethods) @response_class = @response_class.dup SET_TEMPORARY_NAME[@response_class, pl] @response_class.__send__(:include, pl::ResponseMethods) if defined?(pl::ResponseMethods) @response_class.extend(pl::ResponseClassMethods) if defined?(pl::ResponseClassMethods) end # extend headers class if defined?(pl::HeadersMethods) || defined?(pl::HeadersClassMethods) @headers_class = @headers_class.dup SET_TEMPORARY_NAME[@headers_class, pl] @headers_class.__send__(:include, pl::HeadersMethods) if defined?(pl::HeadersMethods) @headers_class.extend(pl::HeadersClassMethods) if defined?(pl::HeadersClassMethods) end # extend request body class if defined?(pl::RequestBodyMethods) || defined?(pl::RequestBodyClassMethods) @request_body_class = @request_body_class.dup SET_TEMPORARY_NAME[@request_body_class, pl] @request_body_class.__send__(:include, pl::RequestBodyMethods) if defined?(pl::RequestBodyMethods) @request_body_class.extend(pl::RequestBodyClassMethods) if defined?(pl::RequestBodyClassMethods) end # extend response body class if defined?(pl::ResponseBodyMethods) || defined?(pl::ResponseBodyClassMethods) @response_body_class = @response_body_class.dup SET_TEMPORARY_NAME[@response_body_class, pl] @response_body_class.__send__(:include, pl::ResponseBodyMethods) if defined?(pl::ResponseBodyMethods) @response_body_class.extend(pl::ResponseBodyClassMethods) if defined?(pl::ResponseBodyClassMethods) end # extend connection pool class if defined?(pl::PoolMethods) @pool_class = @pool_class.dup SET_TEMPORARY_NAME[@pool_class, pl] @pool_class.__send__(:include, pl::PoolMethods) end # extend connection class if defined?(pl::ConnectionMethods) @connection_class = @connection_class.dup SET_TEMPORARY_NAME[@connection_class, pl] @connection_class.__send__(:include, pl::ConnectionMethods) end # extend http1 class if defined?(pl::HTTP1Methods) @http1_class = @http1_class.dup SET_TEMPORARY_NAME[@http1_class, pl] @http1_class.__send__(:include, pl::HTTP1Methods) end # extend http2 class if defined?(pl::HTTP2Methods) @http2_class = @http2_class.dup SET_TEMPORARY_NAME[@http2_class, pl] @http2_class.__send__(:include, pl::HTTP2Methods) end # extend native resolver class if defined?(pl::ResolverNativeMethods) @resolver_native_class = @resolver_native_class.dup SET_TEMPORARY_NAME[@resolver_native_class, pl] @resolver_native_class.__send__(:include, pl::ResolverNativeMethods) end # extend system resolver class if defined?(pl::ResolverSystemMethods) @resolver_system_class = @resolver_system_class.dup SET_TEMPORARY_NAME[@resolver_system_class, pl] @resolver_system_class.__send__(:include, pl::ResolverSystemMethods) end # extend https resolver class if defined?(pl::ResolverHTTPSMethods) @resolver_https_class = @resolver_https_class.dup SET_TEMPORARY_NAME[@resolver_https_class, pl] @resolver_https_class.__send__(:include, pl::ResolverHTTPSMethods) end return unless defined?(pl::OptionsMethods) # extend option class # works around lack of initialize_dup callback @options_class = @options_class.dup # (self.class.options_names) @options_class.__send__(:include, pl::OptionsMethods) end |
#freeze ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/httpx/options.rb', line 193 def freeze self.class..each do |ivar| # avoid freezing debug option, as when it's set, it's usually an # object which cannot be frozen, like stderr or stdout. It's a # documented exception then, and still does not defeat the purpose # here, which is to make option objects shareable across ractors, # and in most cases debug should be nil, or one of the objects # which will eventually be shareable, like STDOUT or STDERR. next if %i[debug io].include?(ivar) send(ivar).freeze end super end |
#merge(other) ⇒ instance, self
returns a HTTPX::Options instance resulting of the merging of other with self.
it may return self if other is self or equal to self.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/httpx/options.rb', line 246 def merge(other) if ( = other.is_a?(Options)) return self if eql?(other) opts_names = other.class. return self if opts_names.all? { |opt| public_send(opt) == other.public_send(opt) } other_opts = opts_names else other_opts = other #: Hash[Symbol, untyped] other_opts = Hash[other] unless other.is_a?(Hash) return self if other_opts.empty? return self if other_opts.all? do |opt, v| unless respond_to?(opt) # TODO: do this instead in a major or minor version bump # raise Error, "unknown option: #{opt}" unless respond_to?(opt) warn "DEPRECATION WARNING: unknown option: `:#{opt}`. an exception will be raised in a future version." next(true) end !respond_to?(opt) || public_send(opt) == v end end opts = dup other_opts.each do |opt, v| next unless respond_to?(opt) v = other.public_send(opt) if ivar = :"@#{opt}" unless v opts.instance_variable_set(ivar, v) next end v = opts.__send__(:"option_#{opt}", v) orig_v = public_send(opt) v = orig_v.merge(v) if orig_v.respond_to?(:merge) && v.respond_to?(:merge) opts.instance_variable_set(ivar, v) end opts.freeze opts end |
#resolver_cache ⇒ Object & Resolver::_Cache
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/httpx/options.rb', line 173 def resolver_cache cache_type = @resolver_cache case cache_type when :memory Resolver::Cache::Memory.cache(cache_type) when :file Resolver::Cache::File.cache(cache_type) else unless cache_type.respond_to?(:resolve) && cache_type.respond_to?(:get) && cache_type.respond_to?(:set) && cache_type.respond_to?(:evict) raise TypeError, "`:resolver_cache` must be a compatible resolver cache and implement `#get`, `#set` and `#evict`" end cache_type #: Object & Resolver::_Cache end end |
#resolver_class ⇒ singleton(Resolver::Resolver)
returns the class with which to instantiate the DNS resolver.
164 165 166 167 168 169 170 171 |
# File 'lib/httpx/options.rb', line 164 def resolver_class case @resolver_class when Symbol public_send(:"resolver_#{@resolver_class}_class") else @resolver_class end end |
#resolver_options_match?(other) ⇒ Boolean
checks whether other matches the same resolver-level options
237 238 239 240 241 242 |
# File 'lib/httpx/options.rb', line 237 def (other) self == other || RESOLVER_IVARS.all? do |ivar| instance_variable_get(ivar) == other.instance_variable_get(ivar) end end |
#to_hash ⇒ Hash[Symbol, untyped]
300 301 302 303 304 305 306 307 308 |
# File 'lib/httpx/options.rb', line 300 def to_hash instance_variables.each_with_object({}) do |ivar, hs| val = instance_variable_get(ivar) next if val.nil? hs[ivar[1..-1].to_sym] = val end end |