Methods
Public Class
Public Instance
Classes and Modules
Constants
BUFFER_SIZE | = | 1 << 14 | ||
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, :buffer_size => BUFFER_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 104 def def_option(optname, *args, &block) 105 if args.empty? && !block 106 class_eval(<<-OUT, __FILE__, __LINE__ + 1) 107 def option_#{optname}(v); v; end # def option_smth(v); v; end 108 OUT 109 return 110 end 111 112 deprecated_def_option(optname, *args, &block) 113 end
deprecated_def_option(optname, layout = nil, &interpreter)
[show source]
# File lib/httpx/options.rb 115 def deprecated_def_option(optname, layout = nil, &interpreter) 116 warn "DEPRECATION WARNING: using `def_option(#{optname})` for setting options is deprecated. " \ 117 "Define module OptionsMethods and `def option_#{optname}(val)` instead." 118 119 if layout 120 class_eval(<<-OUT, __FILE__, __LINE__ + 1) 121 def option_#{optname}(value) # def option_origin(v) 122 #{layout} # URI(v) 123 end # end 124 OUT 125 elsif interpreter 126 define_method(:"option_#{optname}") do |value| 127 instance_exec(value, &interpreter) 128 end 129 end 130 end
method_added(meth)
[show source]
# File lib/httpx/options.rb 94 def method_added(meth) 95 super 96 97 return unless meth =~ /^option_(.+)$/ 98 99 optname = Regexp.last_match(1).to_sym 100 101 attr_reader(optname) 102 end
new(options = {})
[show source]
# File lib/httpx/options.rb 86 def new(options = {}) 87 # let enhanced options go through 88 return options if self == Options && options.class < self 89 return options if options.is_a?(self) 90 91 super 92 end
new(options = {})
[show source]
# File lib/httpx/options.rb 133 def initialize(options = {}) 134 __initialize__(options) 135 freeze 136 end
Public Instance methods
==(other)
[show source]
# File lib/httpx/options.rb 230 def ==(other) 231 ivars = instance_variables | other.instance_variables 232 ivars.all? do |ivar| 233 case ivar 234 when :@headers 235 # currently, this is used to pick up an available matching connection. 236 # the headers do not play a role, as they are relevant only for the request. 237 true 238 when *REQUEST_IVARS 239 true 240 else 241 instance_variable_get(ivar) == other.instance_variable_get(ivar) 242 end 243 end 244 end
freeze()
[show source]
# File lib/httpx/options.rb 138 def freeze 139 super 140 @origin.freeze 141 @base_path.freeze 142 @timeout.freeze 143 @headers.freeze 144 @addresses.freeze 145 end
initialize_dup(other)
[show source]
# File lib/httpx/options.rb 274 def initialize_dup(other) 275 instance_variables.each do |ivar| 276 instance_variable_set(ivar, other.instance_variable_get(ivar).dup) 277 end 278 end
merge(other)
[show source]
# File lib/httpx/options.rb 246 def merge(other) 247 raise ArgumentError, "#{other} is not a valid set of options" unless other.respond_to?(:to_hash) 248 249 h2 = other.to_hash 250 return self if h2.empty? 251 252 h1 = to_hash 253 254 return self if h1 >= h2 255 256 merged = h1.merge(h2) do |_k, v1, v2| 257 if v1.respond_to?(:merge) && v2.respond_to?(:merge) 258 v1.merge(v2) 259 else 260 v2 261 end 262 end 263 264 self.class.new(merged) 265 end
option_addresses(value)
[show source]
# File lib/httpx/options.rb 209 def option_addresses(value) 210 Array(value) 211 end
option_base_path(value)
[show source]
# File lib/httpx/options.rb 151 def option_base_path(value) 152 String(value) 153 end
option_body_threshold_size(value)
[show source]
# File lib/httpx/options.rb 198 def option_body_threshold_size(value) 199 Integer(value) 200 end
option_buffer_size(value)
[show source]
# File lib/httpx/options.rb 190 def option_buffer_size(value) 191 value = Integer(value) 192 193 raise TypeError, ":buffer_size must be positive" unless value.positive? 194 195 value 196 end
option_headers(value)
[show source]
# File lib/httpx/options.rb 155 def option_headers(value) 156 Headers.new(value) 157 end
option_ip_families(value)
[show source]
# File lib/httpx/options.rb 213 def option_ip_families(value) 214 Array(value) 215 end
option_max_concurrent_requests(value)
[show source]
# File lib/httpx/options.rb 170 def option_max_concurrent_requests(value) 171 raise TypeError, ":max_concurrent_requests must be positive" unless value.positive? 172 173 value 174 end
option_max_requests(value)
[show source]
# File lib/httpx/options.rb 176 def option_max_requests(value) 177 raise TypeError, ":max_requests must be positive" unless value.positive? 178 179 value 180 end
option_origin(value)
[show source]
# File lib/httpx/options.rb 147 def option_origin(value) 148 URI(value) 149 end
option_timeout(value)
[show source]
# File lib/httpx/options.rb 159 def option_timeout(value) 160 timeouts = Hash[value] 161 162 if timeouts.key?(:loop_timeout) 163 warn ":loop_timeout is deprecated, use :operation_timeout instead" 164 timeouts[:operation_timeout] = timeouts.delete(:loop_timeout) 165 end 166 167 timeouts 168 end
option_transport(value)
[show source]
# File lib/httpx/options.rb 202 def option_transport(value) 203 transport = value.to_s 204 raise TypeError, "#{transport} is an unsupported transport type" unless %w[unix].include?(transport) 205 206 transport 207 end
option_window_size(value)
[show source]
# File lib/httpx/options.rb 182 def option_window_size(value) 183 value = Integer(value) 184 185 raise TypeError, ":window_size must be positive" unless value.positive? 186 187 value 188 end
to_hash()
[show source]
# File lib/httpx/options.rb 267 def to_hash 268 instance_variables.each_with_object({}) do |ivar, hs| 269 hs[ivar[1..-1].to_sym] = instance_variable_get(ivar) 270 end 271 end