class HTTPX::Options

  1. lib/httpx/options.rb
Superclass: Object

Classes and Modules

  1. HTTPX::Options::HashExtensions

Constants

CONNECT_TIMEOUT = 60  
DEFAULT_OPTIONS = { :debug => ENV.key?("HTTPX_DEBUG") ? $stderr : nil, :debug_level => (ENV["HTTPX_DEBUG"] || 1).to_i, :ssl => {}, :http2_settings => { settings_enable_push: 0 }, :fallback_protocol => "http/1.1", :timeout => { connect_timeout: CONNECT_TIMEOUT, settings_timeout: SETTINGS_TIMEOUT, operation_timeout: OPERATION_TIMEOUT, keep_alive_timeout: KEEP_ALIVE_TIMEOUT, read_timeout: READ_TIMEOUT, write_timeout: WRITE_TIMEOUT, request_timeout: REQUEST_TIMEOUT, }, :headers => {}, :window_size => WINDOW_SIZE, :body_threshold_size => MAX_BODY_THRESHOLD_SIZE, :request_class => Class.new(Request), :response_class => Class.new(Response), :headers_class => Class.new(Headers), :request_body_class => Class.new(Request::Body), :response_body_class => Class.new(Response::Body), :connection_class => Class.new(Connection), :options_class => Class.new(self), :transport => nil, :transport_options => nil, :addresses => nil, :persistent => false, :resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym, :resolver_options => { cache: true }, :ip_families => ip_address_families, }.freeze  
KEEP_ALIVE_TIMEOUT = 20  
MAX_BODY_THRESHOLD_SIZE = (1 << 10) * 112  
OPERATION_TIMEOUT = 60  
READ_TIMEOUT = WRITE_TIMEOUT = REQUEST_TIMEOUT = Float::INFINITY  
SETTINGS_TIMEOUT = 10  
WINDOW_SIZE = 1 << 14  

Public Class methods

def_option(optname, *args, &block)
[show source]
    # File lib/httpx/options.rb
102       def def_option(optname, *args, &block)
103         if args.empty? && !block
104           class_eval(<<-OUT, __FILE__, __LINE__ + 1)
105             def option_#{optname}(v); v; end # def option_smth(v); v; end
106           OUT
107           return
108         end
109 
110         deprecated_def_option(optname, *args, &block)
111       end
deprecated_def_option(optname, layout = nil, &interpreter)
[show source]
    # File lib/httpx/options.rb
113       def deprecated_def_option(optname, layout = nil, &interpreter)
114         warn "DEPRECATION WARNING: using `def_option(#{optname})` for setting options is deprecated. " \
115              "Define module OptionsMethods and `def option_#{optname}(val)` instead."
116 
117         if layout
118           class_eval(<<-OUT, __FILE__, __LINE__ + 1)
119             def option_#{optname}(value)  # def option_origin(v)
120               #{layout}                   #   URI(v)
121             end                           # end
122           OUT
123         elsif interpreter
124           define_method(:"option_#{optname}") do |value|
125             instance_exec(value, &interpreter)
126           end
127         end
128       end
method_added(meth)
[show source]
    # File lib/httpx/options.rb
 92 def method_added(meth)
 93   super
 94 
 95   return unless meth =~ /^option_(.+)$/
 96 
 97   optname = Regexp.last_match(1).to_sym
 98 
 99   attr_reader(optname)
100 end
new(options = {})
[show source]
   # File lib/httpx/options.rb
84 def new(options = {})
85   # let enhanced options go through
86   return options if self == Options && options.class < self
87   return options if options.is_a?(self)
88 
89   super
90 end
new(options = {})
[show source]
    # File lib/httpx/options.rb
131 def initialize(options = {})
132   __initialize__(options)
133   freeze
134 end

Public Instance methods

==(other)
[show source]
    # File lib/httpx/options.rb
216 def ==(other)
217   ivars = instance_variables | other.instance_variables
218   ivars.all? do |ivar|
219     case ivar
220     when :@headers
221       # currently, this is used to pick up an available matching connection.
222       # the headers do not play a role, as they are relevant only for the request.
223       true
224     when *REQUEST_IVARS
225       true
226     else
227       instance_variable_get(ivar) == other.instance_variable_get(ivar)
228     end
229   end
230 end
freeze()
[show source]
    # File lib/httpx/options.rb
136 def freeze
137   super
138   @origin.freeze
139   @base_path.freeze
140   @timeout.freeze
141   @headers.freeze
142   @addresses.freeze
143 end
initialize_dup(other)
[show source]
    # File lib/httpx/options.rb
260 def initialize_dup(other)
261   instance_variables.each do |ivar|
262     instance_variable_set(ivar, other.instance_variable_get(ivar).dup)
263   end
264 end
merge(other)
[show source]
    # File lib/httpx/options.rb
232 def merge(other)
233   raise ArgumentError, "#{other} is not a valid set of options" unless other.respond_to?(:to_hash)
234 
235   h2 = other.to_hash
236   return self if h2.empty?
237 
238   h1 = to_hash
239 
240   return self if h1 >= h2
241 
242   merged = h1.merge(h2) do |_k, v1, v2|
243     if v1.respond_to?(:merge) && v2.respond_to?(:merge)
244       v1.merge(v2)
245     else
246       v2
247     end
248   end
249 
250   self.class.new(merged)
251 end
option_addresses(value)
[show source]
    # File lib/httpx/options.rb
195 def option_addresses(value)
196   Array(value)
197 end
option_base_path(value)
[show source]
    # File lib/httpx/options.rb
149 def option_base_path(value)
150   String(value)
151 end
option_body_threshold_size(value)
[show source]
    # File lib/httpx/options.rb
184 def option_body_threshold_size(value)
185   Integer(value)
186 end
option_headers(value)
[show source]
    # File lib/httpx/options.rb
153 def option_headers(value)
154   Headers.new(value)
155 end
option_ip_families(value)
[show source]
    # File lib/httpx/options.rb
199 def option_ip_families(value)
200   Array(value)
201 end
option_max_concurrent_requests(value)
[show source]
    # File lib/httpx/options.rb
168 def option_max_concurrent_requests(value)
169   raise TypeError, ":max_concurrent_requests must be positive" unless value.positive?
170 
171   value
172 end
option_max_requests(value)
[show source]
    # File lib/httpx/options.rb
174 def option_max_requests(value)
175   raise TypeError, ":max_requests must be positive" unless value.positive?
176 
177   value
178 end
option_origin(value)
[show source]
    # File lib/httpx/options.rb
145 def option_origin(value)
146   URI(value)
147 end
option_timeout(value)
[show source]
    # File lib/httpx/options.rb
157 def option_timeout(value)
158   timeouts = Hash[value]
159 
160   if timeouts.key?(:loop_timeout)
161     warn ":loop_timeout is deprecated, use :operation_timeout instead"
162     timeouts[:operation_timeout] = timeouts.delete(:loop_timeout)
163   end
164 
165   timeouts
166 end
option_transport(value)
[show source]
    # File lib/httpx/options.rb
188 def option_transport(value)
189   transport = value.to_s
190   raise TypeError, "\#{transport} is an unsupported transport type" unless IO.registry.key?(transport)
191 
192   transport
193 end
option_window_size(value)
[show source]
    # File lib/httpx/options.rb
180 def option_window_size(value)
181   Integer(value)
182 end
to_hash()
[show source]
    # File lib/httpx/options.rb
253 def to_hash
254   instance_variables.each_with_object({}) do |ivar, hs|
255     hs[ivar[1..-1].to_sym] = instance_variable_get(ivar)
256   end
257 end