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.
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
- REQUEST_TIMEOUT =
OPERATION_TIMEOUT = TOTAL_REQUEST_TIMEOUT = nil
- 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 => { connect_timeout: CONNECT_TIMEOUT, settings_timeout: SETTINGS_TIMEOUT, close_handshake_timeout: CLOSE_HANDSHAKE_TIMEOUT, operation_timeout: OPERATION_TIMEOUT, keep_alive_timeout: KEEP_ALIVE_TIMEOUT, ping_timeout: PING_TIMEOUT, read_timeout: READ_TIMEOUT, write_timeout: WRITE_TIMEOUT, request_timeout: REQUEST_TIMEOUT, total_request_timeout: TOTAL_REQUEST_TIMEOUT, }.freeze, :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 =
- TOTAL_REQUEST_TIMEOUT =
- OPERATION_TIMEOUT =
Class Attribute Summary collapse
-
.options_names ⇒ Array[Symbol]
readonly
Returns the value of attribute options_names.
Instance Attribute Summary collapse
-
#addresses ⇒ 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 ⇒ timeout
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
- #access_option(obj, k, ivar_map) ⇒ Object
-
#connection_options_match?(other, ignore_ivars = nil) ⇒ Boolean
checks whether
othermatches the same connection-level options. -
#do_initialize ⇒ void
called after all options are initialized.
- #extend_with_plugin_classes(pl) ⇒ void
- #freeze ⇒ Object
-
#initialize(options = EMPTY_HASH) ⇒ Options
constructor
creates a new options instance from a given hash, which optionally define the following:.
-
#merge(other) ⇒ instance, self
returns a HTTPX::Options instance resulting of the merging of
otherwith self. - #option_addresses(value) ⇒ Array[ipaddr]
- #option_base_path(value) ⇒ String
- #option_body_threshold_size ⇒ Integer
- #option_buffer_size ⇒ Integer
- #option_close_on_fork ⇒ Boolean
- #option_compress_request_body ⇒ Boolean
- #option_connection_class ⇒ singleton(Connection)
- #option_debug ⇒ _IOLogger
- #option_debug_level ⇒ Integer
- #option_debug_redact ⇒ redact_value
- #option_decompress_response_body ⇒ Boolean
- #option_fallback_protocol ⇒ String
- #option_headers(value) ⇒ Headers
- #option_headers_class ⇒ singleton(Headers)
- #option_http2_settings ⇒ Hash[Symbol, untyped]
- #option_io ⇒ io_option
- #option_ip_families(value) ⇒ Array[ip_family]
-
#option_max_concurrent_requests ⇒ maybe_unbounded
integer.
- #option_max_requests ⇒ maybe_unbounded
- #option_options_class ⇒ singleton(Options)
- #option_origin(value) ⇒ http_uri
- #option_persistent ⇒ Boolean
- #option_pool_class ⇒ singleton(Pool)
- #option_pool_options ⇒ Hash[Symbol, untyped]
- #option_request_body_class ⇒ singleton(Request::Body)
-
#option_request_class ⇒ singleton(Request)
no transform.
- #option_resolver_cache(cache_type) ⇒ resolver_cache_option
- #option_resolver_class(resolver_type) ⇒ Symbol, resolver_type
- #option_resolver_options ⇒ Hash[Symbol, untyped]
- #option_response_body_class ⇒ singleton(Response::Body)
- #option_response_class ⇒ singleton(Response)
-
#option_ssl ⇒ Hash[Symbol, untyped]
to hash.
- #option_supported_compression_formats(value) ⇒ Array[String]
- #option_timeout(value) ⇒ timeout
- #option_transport(value) ⇒ String
- #option_window_size ⇒ Integer
- #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]
Constructor Details
#initialize(options = EMPTY_HASH) ⇒ Options
creates a new options instance from a given hash, which optionally define the following:
:debug :: an object which log messages are written to (must respond to <<) :debug_level :: the log level of messages (can be 1, 2, or 3). :debug_redact :: whether header/body payload should be redacted (defaults to false). :ssl :: a hash of options which can be set as params of OpenSSL::SSL::SSLContext (see HTTPX::SSL) :http2_settings :: a hash of options to be passed to a HTTP2::Connection (ex: { max_concurrent_streams: 2 }) :fallback_protocol :: version of HTTP protocol to use by default in the absence of protocol negotiation like ALPN (defaults to "http/1.1") :supported_compression_formats :: list of compressions supported by the transcoder layer (defaults to %w[gzip deflate]). :decompress_response_body :: whether to auto-decompress response body (defaults to true). :compress_request_body :: whether to auto-decompress response body (defaults to true) :timeout :: hash of timeout configurations (supports :connect_timeout, :settings_timeout, :operation_timeout, :keep_alive_timeout, :read_timeout, :write_timeout, :request_timeout, :total_request_timeout and :ping_timeout, :headers :: hash of HTTP headers (ex: { "x-custom-foo" => "bar" }) :max_response_body_size :: maximum size (in bytes) that the response body can consume (no threshold by default), after which an error is raised. :max_response_headers :: maximum number of header fields that a response can receive, after which an error is raised. :max_response_header_value_size :: maximum size (in bytes) a header value can have (no threshold by default). for cases where the value is broken into multiple header fields (such as "cookie" or "set-cookie"), this is the total aggregated size. :window_size :: number of bytes to read from a socket :buffer_size :: internal read and write buffer size in bytes :body_threshold_size :: maximum size in bytes of response payload that is buffered in memory. :request_class :: class used to instantiate a request :response_class :: class used to instantiate a response :headers_class :: class used to instantiate headers :request_body_class :: class used to instantiate a request body :response_body_class :: class used to instantiate a response body :connection_class :: class used to instantiate connections :http1_class :: class used to manage HTTP1 sessions :http2_class :: class used to imanage HTTP2 sessions :resolver_native_class :: class used to resolve names using pure ruby DNS implementation :resolver_system_class :: class used to resolve names using system-based (getaddrinfo) name resolution :resolver_https_class :: class used to resolve names using DoH :pool_class :: class used to instantiate the session connection pool :options_class :: class used to instantiate options :transport :: type of transport to use (set to "unix" for UNIX sockets) :addresses :: bucket of peer addresses (can be a list of IP addresses, a hash of domain to list of adddresses; paths should be used for UNIX sockets instead) :io :: open socket, or domain/ip-to-socket hash, which requests should be sent to :persistent :: whether to persist connections in between requests (defaults to true) :resolver_class :: which resolver to use (defaults to :native, can also be :system for using getaddrinfo or :https for DoH resolver, or a custom class inheriting from HTTPX::Resolver::Resolver) :resolver_cache :: strategy to cache DNS results, ignored by the :system resolver, can be set to :memory or an instance of a custom class inheriting from HTTPX::Resolver::Cache::Base :resolver_options :: hash of options passed to the resolver. Accepted keys depend on the resolver type. :pool_options :: hash of options passed to the connection pool (See Pool#initialize). :ip_families :: which socket families are supported (system-dependent) :origin :: HTTP origin to set on requests with relative path (ex: "https://api.serv.com") :base_path :: path to prefix given relative paths with (ex: "/v2") :max_concurrent_requests :: max number of requests which can be set concurrently :max_requests :: max number of requests which can be made on socket before it reconnects. :close_on_fork :: whether the session automatically closes when the process is fork (defaults to false). it only works if the session is persistent (and ruby 3.1 or higher is used).
This list of options are enhanced with each loaded plugin, see the plugin docs for details.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/httpx/options.rb', line 128 def initialize( = EMPTY_HASH) = self.class. defaults = case when Options = .class. - raise Error, "unknown option: `:#{.first}`" unless .empty? DEFAULT_OPTIONS.merge() else .each_key do |k| raise Error, "unknown option: `:#{k}`" unless .include?(k) end .empty? ? DEFAULT_OPTIONS : DEFAULT_OPTIONS.merge() end .each do |k| v = defaults[k] if v.nil? instance_variable_set(:"@#{k}", v) next end value = __send__(:"option_#{k}", v) instance_variable_set(:"@#{k}", value) end do_initialize freeze end |
Class Attribute Details
.options_names ⇒ Array[Symbol] (readonly)
Returns the value of attribute options_names.
23 24 25 |
# File 'lib/httpx/options.rb', line 23 def @options_names end |
Instance Attribute Details
#addresses ⇒ Array[Resolver::Entry]? (readonly)
addresses
77 78 79 |
# File 'sig/options.rbs', line 77 def addresses @addresses end |
#base_path ⇒ String? (readonly)
base_path
92 93 94 |
# File 'sig/options.rbs', line 92 def base_path @base_path end |
#body_threshold_size ⇒ Integer (readonly)
body_threshold_size
62 63 64 |
# File 'sig/options.rbs', line 62 def body_threshold_size @body_threshold_size end |
#buffer_size ⇒ Integer (readonly)
buffer_size
59 60 61 |
# File 'sig/options.rbs', line 59 def buffer_size @buffer_size end |
#close_on_fork ⇒ Boolean (readonly)
close_on_fork
142 143 144 |
# File 'sig/options.rbs', line 142 def close_on_fork @close_on_fork end |
#compress_request_body ⇒ Boolean (readonly)
compress_request_body
83 84 85 |
# File 'sig/options.rbs', line 83 def compress_request_body @compress_request_body end |
#connection_class ⇒ singleton(Connection) (readonly)
Returns the value of attribute connection_class.
105 106 107 |
# File 'sig/options.rbs', line 105 def connection_class @connection_class end |
#debug ⇒ _IOLogger? (readonly)
debug
133 134 135 |
# File 'sig/options.rbs', line 133 def debug @debug end |
#debug_level ⇒ Integer (readonly)
debug_level
136 137 138 |
# File 'sig/options.rbs', line 136 def debug_level @debug_level end |
#decompress_response_body ⇒ Boolean (readonly)
decompress_response_body
86 87 88 |
# File 'sig/options.rbs', line 86 def decompress_response_body @decompress_response_body end |
#fallback_protocol ⇒ String (readonly)
fallback_protocol
130 131 132 |
# File 'sig/options.rbs', line 130 def fallback_protocol @fallback_protocol end |
#headers ⇒ headers? (readonly)
headers
41 42 43 |
# File 'sig/options.rbs', line 41 def headers @headers end |
#headers_class ⇒ singleton(Headers) (readonly)
Returns the value of attribute headers_class.
113 114 115 |
# File 'sig/options.rbs', line 113 def headers_class @headers_class end |
#http1_class ⇒ singleton(Connection::HTTP1) (readonly)
Returns the value of attribute http1_class.
101 102 103 |
# File 'sig/options.rbs', line 101 def http1_class @http1_class end |
#http2_class ⇒ singleton(Connection::HTTP2) (readonly)
Returns the value of attribute http2_class.
103 104 105 |
# File 'sig/options.rbs', line 103 def http2_class @http2_class end |
#http2_settings ⇒ Hash[Symbol, Integer | bool] (readonly)
http2_settings
47 48 49 |
# File 'sig/options.rbs', line 47 def http2_settings @http2_settings end |
#io ⇒ io_option? (readonly)
Returns the value of attribute io.
127 128 129 |
# File 'sig/options.rbs', line 127 def io @io end |
#ip_families ⇒ Array[ip_family]? (readonly)
ip_families
151 152 153 |
# File 'sig/options.rbs', line 151 def ip_families @ip_families end |
#max_concurrent_requests ⇒ maybe_unbounded? (readonly)
max_concurrent_requests
50 51 52 |
# File 'sig/options.rbs', line 50 def max_concurrent_requests @max_concurrent_requests end |
#max_requests ⇒ maybe_unbounded? (readonly)
max_requests
53 54 55 |
# File 'sig/options.rbs', line 53 def max_requests @max_requests end |
#max_response_body_size ⇒ maybe_unbounded (readonly)
max_response_body_size
71 72 73 |
# File 'sig/options.rbs', line 71 def max_response_body_size @max_response_body_size end |
#max_response_header_value_size ⇒ maybe_unbounded? (readonly)
max_response_header_value_size
68 69 70 |
# File 'sig/options.rbs', line 68 def max_response_header_value_size @max_response_header_value_size end |
#max_response_headers ⇒ Integer (readonly)
max_response_headers
65 66 67 |
# File 'sig/options.rbs', line 65 def max_response_headers @max_response_headers end |
#options_class ⇒ singleton(Options) (readonly)
Returns the value of attribute options_class.
119 120 121 |
# File 'sig/options.rbs', line 119 def @options_class end |
#origin ⇒ URI::Generic? (readonly)
origin
89 90 91 |
# File 'sig/options.rbs', line 89 def origin @origin end |
#persistent ⇒ Boolean (readonly)
persistent
139 140 141 |
# File 'sig/options.rbs', line 139 def persistent @persistent end |
#pool_class ⇒ singleton(Pool) (readonly)
Returns the value of attribute pool_class.
107 108 109 |
# File 'sig/options.rbs', line 107 def pool_class @pool_class end |
#pool_options ⇒ pool_options (readonly)
resolver_options
148 149 150 |
# File 'sig/options.rbs', line 148 def @pool_options end |
#request_body_class ⇒ singleton(Request::Body) (readonly)
Returns the value of attribute request_body_class.
115 116 117 |
# File 'sig/options.rbs', line 115 def request_body_class @request_body_class end |
#request_class ⇒ singleton(Request) (readonly)
Returns the value of attribute request_class.
109 110 111 |
# File 'sig/options.rbs', line 109 def request_class @request_class end |
#resolver_https_class ⇒ singleton(Resolver::HTTPS) (readonly)
Returns the value of attribute resolver_https_class.
99 100 101 |
# File 'sig/options.rbs', line 99 def resolver_https_class @resolver_https_class end |
#resolver_native_class ⇒ singleton(Resolver::Native) (readonly)
classes
95 96 97 |
# File 'sig/options.rbs', line 95 def resolver_native_class @resolver_native_class end |
#resolver_options ⇒ Hash[Symbol, untyped] (readonly)
resolver_options
145 146 147 |
# File 'sig/options.rbs', line 145 def @resolver_options end |
#resolver_system_class ⇒ singleton(Resolver::System) (readonly)
Returns the value of attribute resolver_system_class.
97 98 99 |
# File 'sig/options.rbs', line 97 def resolver_system_class @resolver_system_class end |
#response_body_class ⇒ singleton(Response::Body) (readonly)
Returns the value of attribute response_body_class.
117 118 119 |
# File 'sig/options.rbs', line 117 def response_body_class @response_body_class end |
#response_class ⇒ singleton(Response) (readonly)
Returns the value of attribute response_class.
111 112 113 |
# File 'sig/options.rbs', line 111 def response_class @response_class end |
#ssl ⇒ Hash[Symbol, untyped] (readonly)
Returns the value of attribute ssl.
121 122 123 |
# File 'sig/options.rbs', line 121 def ssl @ssl end |
#supported_compression_formats ⇒ Array[String] (readonly)
supported_compression_formats
80 81 82 |
# File 'sig/options.rbs', line 80 def supported_compression_formats @supported_compression_formats end |
#timeout ⇒ timeout (readonly)
timeout
44 45 46 |
# File 'sig/options.rbs', line 44 def timeout @timeout end |
#transport ⇒ io_type? (readonly)
transport
74 75 76 |
# File 'sig/options.rbs', line 74 def transport @transport end |
#uri ⇒ URI? (readonly)
headers
38 39 40 |
# File 'sig/options.rbs', line 38 def uri @uri end |
#window_size ⇒ Integer (readonly)
window_size
56 57 58 |
# File 'sig/options.rbs', line 56 def window_size @window_size end |
Class Method Details
.freeze ⇒ Object
38 39 40 41 |
# File 'lib/httpx/options.rb', line 38 def freeze @options_names.freeze super end |
.inherited(klass) ⇒ Object
25 26 27 28 |
# File 'lib/httpx/options.rb', line 25 def inherited(klass) super klass.instance_variable_set(:@options_names, @options_names.dup) end |
.method_added(meth) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/httpx/options.rb', line 43 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
30 31 32 33 34 35 36 |
# File 'lib/httpx/options.rb', line 30 def new( = {}) # let enhanced options go through return if self == Options && .class < self return if .is_a?(self) super end |
Instance Method Details
#== ⇒ Boolean
159 |
# File 'sig/options.rbs', line 159
def ==: (Options other) -> bool
|
#access_option(obj, k, ivar_map) ⇒ Object
542 543 544 545 546 547 548 549 |
# File 'lib/httpx/options.rb', line 542 def access_option(obj, k, ivar_map) case obj when Hash obj[ivar_map[k]] else obj.instance_variable_get(k) end end |
#connection_options_match?(other, ignore_ivars = nil) ⇒ Boolean
checks whether other matches the same connection-level options
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/httpx/options.rb', line 212 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 = instance_variables ivars.reject! { |iv| REQUEST_BODY_IVARS.include?(iv) } ivars.reject! { |iv| ignore_ivars.include?(iv) } if ignore_ivars other_ivars = other.instance_variables other_ivars.reject! { |iv| REQUEST_BODY_IVARS.include?(iv) } other_ivars.reject! { |iv| ignore_ivars.include?(iv) } if ignore_ivars return false if ivars.size != other_ivars.size return false if ivars.sort != other_ivars.sort ivars.all? do |ivar| instance_variable_get(ivar) == other.instance_variable_get(ivar) end end |
#do_initialize ⇒ void
This method returns an undefined value.
called after all options are initialized
529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/httpx/options.rb', line 529 def do_initialize hs = @headers # initialized default request headers hs["user-agent"] = USER_AGENT unless hs.key?("user-agent") hs["accept"] = "*/*" unless hs.key?("accept") if hs.key?("range") hs.delete("accept-encoding") else hs["accept-encoding"] = supported_compression_formats unless hs.key?("accept-encoding") end end |
#extend_with_plugin_classes(pl) ⇒ void
This method returns an undefined value.
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 397 398 |
# File 'lib/httpx/options.rb', line 312 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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/httpx/options.rb', line 194 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 ivar == :debug instance_variable_get(:"@#{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.
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 299 300 |
# File 'lib/httpx/options.rb', line 249 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 end |
#option_addresses(value) ⇒ Array[ipaddr]
485 486 487 |
# File 'lib/httpx/options.rb', line 485 def option_addresses(value) Array(value).map { |entry| Resolver::Entry.convert(entry) } end |
#option_base_path(value) ⇒ String
447 448 449 |
# File 'lib/httpx/options.rb', line 447 def option_base_path(value) String(value) end |
#option_body_threshold_size ⇒ Integer
184 |
# File 'sig/options.rbs', line 184
def option_body_threshold_size: (int value) -> Integer
|
#option_buffer_size ⇒ Integer
183 |
# File 'sig/options.rbs', line 183
def option_buffer_size: (int value) -> Integer
|
#option_close_on_fork ⇒ Boolean
210 |
# File 'sig/options.rbs', line 210
def option_close_on_fork: (bool value) -> bool
|
#option_compress_request_body ⇒ Boolean
207 |
# File 'sig/options.rbs', line 207
def option_compress_request_body: (bool value) -> bool
|
#option_connection_class ⇒ singleton(Connection)
199 |
# File 'sig/options.rbs', line 199
def option_connection_class: (singleton(Connection) value) -> singleton(Connection)
|
#option_debug ⇒ _IOLogger
205 |
# File 'sig/options.rbs', line 205
def option_debug: (_IOLogger value) -> _IOLogger
|
#option_debug_level ⇒ Integer
185 |
# File 'sig/options.rbs', line 185
def option_debug_level: (int value) -> Integer
|
#option_debug_redact ⇒ redact_value
206 |
# File 'sig/options.rbs', line 206
def option_debug_redact: (redact_value value) -> redact_value
|
#option_decompress_response_body ⇒ Boolean
208 |
# File 'sig/options.rbs', line 208
def option_decompress_response_body: (bool value) -> bool
|
#option_fallback_protocol ⇒ String
204 |
# File 'sig/options.rbs', line 204
def option_fallback_protocol: (String value) -> String
|
#option_headers(value) ⇒ Headers
451 452 453 454 455 |
# File 'lib/httpx/options.rb', line 451 def option_headers(value) value = value.dup if value.frozen? headers_class.new(value) end |
#option_headers_class ⇒ singleton(Headers)
196 |
# File 'sig/options.rbs', line 196
def option_headers_class: (singleton(Headers) value) -> singleton(Headers)
|
#option_http2_settings ⇒ Hash[Symbol, untyped]
189 |
# File 'sig/options.rbs', line 189
def option_http2_settings: (_ToHash[Symbol, untyped] value) -> Hash[Symbol, untyped]
|
#option_io ⇒ io_option
203 |
# File 'sig/options.rbs', line 203
def option_io: (io_option value) -> io_option
|
#option_ip_families(value) ⇒ Array[ip_family]
489 490 491 |
# File 'lib/httpx/options.rb', line 489 def option_ip_families(value) Array(value) end |
#option_max_concurrent_requests ⇒ maybe_unbounded
integer
180 |
# File 'sig/options.rbs', line 180
def option_max_concurrent_requests: (int value) -> maybe_unbounded
|
#option_max_requests ⇒ maybe_unbounded
181 |
# File 'sig/options.rbs', line 181
def option_max_requests: (int value) -> maybe_unbounded
|
#option_options_class ⇒ singleton(Options)
200 |
# File 'sig/options.rbs', line 200
def option_options_class: (singleton(Options) value) -> singleton(Options)
|
#option_origin(value) ⇒ http_uri
443 444 445 |
# File 'lib/httpx/options.rb', line 443 def option_origin(value) URI(value) end |
#option_persistent ⇒ Boolean
209 |
# File 'sig/options.rbs', line 209
def option_persistent: (bool value) -> bool
|
#option_pool_class ⇒ singleton(Pool)
201 |
# File 'sig/options.rbs', line 201
def option_pool_class: (singleton(Pool) value) -> singleton(Pool)
|
#option_pool_options ⇒ Hash[Symbol, untyped]
191 |
# File 'sig/options.rbs', line 191
def option_pool_options: (_ToHash[Symbol, untyped] value) -> Hash[Symbol, untyped]
|
#option_request_body_class ⇒ singleton(Request::Body)
197 |
# File 'sig/options.rbs', line 197
def option_request_body_class: (singleton(Request::Body) value) -> singleton(Request::Body)
|
#option_request_class ⇒ singleton(Request)
no transform
194 |
# File 'sig/options.rbs', line 194
def option_request_class: (singleton(Request) value) -> singleton(Request)
|
#option_resolver_cache(cache_type) ⇒ resolver_cache_option
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/httpx/options.rb', line 510 def option_resolver_cache(cache_type) if cache_type.is_a?(Symbol) raise TypeError, ":resolver_cache: #{cache_type} is invalid" unless RESOLVER_TYPES.include?(cache_type) require "httpx/resolver/cache/file" if cache_type == :file 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 `#resolve`, `#get`, `#set` and `#evict`" end end cache_type end |
#option_resolver_class(resolver_type) ⇒ Symbol, resolver_type
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/httpx/options.rb', line 493 def option_resolver_class(resolver_type) case resolver_type when Symbol meth = :"resolver_#{resolver_type}_class" raise TypeError, "`:resolver_class` must be a supported type" unless respond_to?(meth) resolver_type when Class raise TypeError, "`:resolver_class` must be a subclass of `#{Resolver::Resolver}`" unless resolver_type < Resolver::Resolver resolver_type else raise TypeError, "`:resolver_class` must be a supported type" end end |
#option_resolver_options ⇒ Hash[Symbol, untyped]
190 |
# File 'sig/options.rbs', line 190
def option_resolver_options: (_ToHash[Symbol, untyped] value) -> Hash[Symbol, untyped]
|
#option_response_body_class ⇒ singleton(Response::Body)
198 |
# File 'sig/options.rbs', line 198
def option_response_body_class: (singleton(Response::Body) value) -> singleton(Response::Body)
|
#option_response_class ⇒ singleton(Response)
195 |
# File 'sig/options.rbs', line 195
def option_response_class: (singleton(Response) value) -> singleton(Response)
|
#option_ssl ⇒ Hash[Symbol, untyped]
to hash
188 |
# File 'sig/options.rbs', line 188
def option_ssl: (_ToHash[Symbol, untyped] value) -> Hash[Symbol, untyped]
|
#option_supported_compression_formats(value) ⇒ Array[String]
474 475 476 |
# File 'lib/httpx/options.rb', line 474 def option_supported_compression_formats(value) Array(value).map(&:to_s) end |
#option_timeout(value) ⇒ timeout
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/httpx/options.rb', line 457 def option_timeout(value) timeout_hash = Hash[value] default_timeouts = DEFAULT_OPTIONS[:timeout] # Validate keys and values timeout_hash.each do |key, val| raise TypeError, "invalid timeout: `:#{key}`" unless default_timeouts.key?(key) next if val.nil? raise TypeError, "`:#{key}` must be numeric" unless val.is_a?(Numeric) end timeout_hash end |
#option_transport(value) ⇒ String
478 479 480 481 482 483 |
# File 'lib/httpx/options.rb', line 478 def option_transport(value) transport = value.to_s raise TypeError, "#{transport} is an unsupported transport type" unless %w[unix].include?(transport) transport end |
#option_window_size ⇒ Integer
182 |
# File 'sig/options.rbs', line 182
def option_window_size: (int value) -> Integer
|
#resolver_cache ⇒ Object & Resolver::_Cache
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/httpx/options.rb', line 174 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.
165 166 167 168 169 170 171 172 |
# File 'lib/httpx/options.rb', line 165 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
240 241 242 243 244 245 |
# File 'lib/httpx/options.rb', line 240 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]
302 303 304 305 306 307 308 309 310 |
# File 'lib/httpx/options.rb', line 302 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 |