class HTTPX::Options

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

Methods

Public Class

  1. def_option
  2. defined_options
  3. inherited
  4. new
  5. new

Public Instance

  1. ==
  2. freeze
  3. initialize_dup
  4. merge
  5. to_hash

Protected Instance

  1. []=

Constants

MAX_BODY_THRESHOLD_SIZE = (1 << 10) * 112  
MAX_CONCURRENT_REQUESTS = 100  
REQUEST_IVARS = %i[@params @form @json @body].freeze  
WINDOW_SIZE = 1 << 14  

Public Class methods

def_option (name, &interpreter)
[show source]
   # File lib/httpx/options.rb
27 def def_option(name, &interpreter)
28   defined_options << name.to_sym
29   interpreter ||= ->(v) { v }
30 
31   attr_accessor name
32   protected :"#{name}="
33 
34   define_method(:"with_#{name}") do |value|
35     other = dup
36     other.send(:"#{name}=", other.instance_exec(value, &interpreter))
37     other
38   end
39 end
defined_options ()
[show source]
   # File lib/httpx/options.rb
23 def defined_options
24   @defined_options ||= []
25 end
inherited (klass)
[show source]
   # File lib/httpx/options.rb
10 def inherited(klass)
11   super
12   klass.instance_variable_set(:@defined_options, @defined_options.dup)
13 end
new (options = {})
[show source]
   # File lib/httpx/options.rb
15 def new(options = {})
16   # let enhanced options go through
17   return options if self == Options && options.class > self
18   return options if options.is_a?(self)
19 
20   super
21 end
new (options = {})
[show source]
   # File lib/httpx/options.rb
42 def initialize(options = {})
43   defaults = {
44     :debug => ENV.key?("HTTPX_DEBUG") ? $stderr : nil,
45     :debug_level => (ENV["HTTPX_DEBUG"] || 1).to_i,
46     :ssl => {},
47     :http2_settings => { settings_enable_push: 0 },
48     :fallback_protocol => "http/1.1",
49     :timeout => Timeout.new,
50     :headers => {},
51     :max_concurrent_requests => MAX_CONCURRENT_REQUESTS,
52     :window_size => WINDOW_SIZE,
53     :body_threshold_size => MAX_BODY_THRESHOLD_SIZE,
54     :request_class => Class.new(Request),
55     :response_class => Class.new(Response),
56     :headers_class => Class.new(Headers),
57     :request_body_class => Class.new(Request::Body),
58     :response_body_class => Class.new(Response::Body),
59     :connection_class => Class.new(Connection),
60     :transport => nil,
61     :transport_options => nil,
62     :persistent => false,
63     :resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym,
64   }
65 
66   defaults.merge!(options)
67   defaults[:headers] = Headers.new(defaults[:headers])
68   defaults.each { |(k, v)| self[k] = v }
69 end

Public Instance methods

== (other)
[show source]
    # File lib/httpx/options.rb
113 def ==(other)
114   ivars = instance_variables | other.instance_variables
115   ivars.all? do |ivar|
116     case ivar
117     when :@headers
118       headers = instance_variable_get(ivar)
119       headers.same_headers?(other.instance_variable_get(ivar))
120     when *REQUEST_IVARS
121       true
122     else
123       instance_variable_get(ivar) == other.instance_variable_get(ivar)
124     end
125   end
126 end
freeze ()
[show source]
    # File lib/httpx/options.rb
162 def freeze
163   super
164 
165   headers.freeze
166   ssl.freeze
167   request_class.freeze
168   response_class.freeze
169   headers_class.freeze
170   request_body_class.freeze
171   response_body_class.freeze
172   connection_class.freeze
173 end
initialize_dup (other)
[show source]
    # File lib/httpx/options.rb
151 def initialize_dup(other)
152   self.headers             = other.headers.dup
153   self.ssl                 = other.ssl.dup
154   self.request_class       = other.request_class.dup
155   self.response_class      = other.response_class.dup
156   self.headers_class       = other.headers_class.dup
157   self.request_body_class  = other.request_body_class.dup
158   self.response_body_class = other.response_body_class.dup
159   self.connection_class    = other.connection_class.dup
160 end
merge (other)
[show source]
    # File lib/httpx/options.rb
128 def merge(other)
129   h1 = to_hash
130   h2 = other.to_hash
131 
132   merged = h1.merge(h2) do |k, v1, v2|
133     case k
134     when :headers, :ssl, :http2_settings, :timeout
135       v1.merge(v2)
136     else
137       v2
138     end
139   end
140 
141   self.class.new(merged)
142 end
to_hash ()
[show source]
    # File lib/httpx/options.rb
144 def to_hash
145   hash_pairs = self.class
146                    .defined_options
147                    .flat_map { |opt_name| [opt_name, send(opt_name)] }
148   Hash[*hash_pairs]
149 end

Protected Instance methods

[]= (option, val)
[show source]
    # File lib/httpx/options.rb
177 def []=(option, val)
178   send(:"#{option}=", val)
179 end