Class: Requests::Http2Adapter
- Inherits:
-
Object
- Object
- Requests::Http2Adapter
- Defined in:
- lib/requests/http2.rb
Instance Attribute Summary collapse
-
#backoff_factor ⇒ Object
Returns the value of attribute backoff_factor.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#status_forcelist ⇒ Object
Returns the value of attribute status_forcelist.
Instance Method Summary collapse
- #close_pool ⇒ Object
- #decode_body(net_resp) ⇒ Object
-
#initialize(max_retries: 0, backoff_factor: 0, status_forcelist: []) ⇒ Http2Adapter
constructor
A new instance of Http2Adapter.
- #send_once(meth, url, hdrs, body, timeout, proxies, verify, cert, auth) ⇒ Object
- #stream_to(meth, url, hdrs, body, timeout, proxies, verify, cert, auth, io, chunk_size: 65_536, progress: nil) ⇒ Object
Constructor Details
#initialize(max_retries: 0, backoff_factor: 0, status_forcelist: []) ⇒ Http2Adapter
Returns a new instance of Http2Adapter.
305 306 307 308 309 310 311 312 |
# File 'lib/requests/http2.rb', line 305 def initialize(max_retries: 0, backoff_factor: 0, status_forcelist: []) @max_retries = max_retries @backoff_factor = backoff_factor @status_forcelist = status_forcelist @pool = {} @alpn = {} @fallback = HTTPAdapter.new(max_retries: max_retries, backoff_factor: backoff_factor, status_forcelist: status_forcelist) end |
Instance Attribute Details
#backoff_factor ⇒ Object
Returns the value of attribute backoff_factor.
304 305 306 |
# File 'lib/requests/http2.rb', line 304 def backoff_factor @backoff_factor end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
304 305 306 |
# File 'lib/requests/http2.rb', line 304 def max_retries @max_retries end |
#status_forcelist ⇒ Object
Returns the value of attribute status_forcelist.
304 305 306 |
# File 'lib/requests/http2.rb', line 304 def status_forcelist @status_forcelist end |
Instance Method Details
#close_pool ⇒ Object
364 365 366 367 368 |
# File 'lib/requests/http2.rb', line 364 def close_pool @pool.each_value { |c| c.close } @pool.clear @fallback.close_pool end |
#decode_body(net_resp) ⇒ Object
361 362 363 |
# File 'lib/requests/http2.rb', line 361 def decode_body(net_resp) @fallback.decode_body(net_resp) end |
#send_once(meth, url, hdrs, body, timeout, proxies, verify, cert, auth) ⇒ Object
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 |
# File 'lib/requests/http2.rb', line 313 def send_once(meth, url, hdrs, body, timeout, proxies, verify, cert, auth) u = URI.parse(url) sync_fallback! return @fallback.send_once(meth, url, hdrs, body, timeout, proxies, verify, cert, auth) unless usable?(u, proxies) conn = conn_for(u, verify, cert, timeout) return @fallback.send_once(meth, url, hdrs, body, timeout, proxies, verify, cert, auth) if conn == :http1 attempt = 0 loop do begin auth.call(hdrs) if auth.respond_to?(:call) && !auth.is_a?(Requests::DigestAuth) resp = perform(conn, meth, u, hdrs, body, timeout) if @status_forcelist.include?(resp.code.to_i) && attempt < @max_retries attempt += 1 sleep(retry_delay(resp, attempt)) conn = conn_for(u, verify, cert, timeout) next end return resp rescue Requests::ConnectionError, Requests::ConnectTimeout => e drop_conn(u) attempt += 1 raise e unless attempt <= @max_retries && idempotent?(meth) sleep(@backoff_factor * attempt) if @backoff_factor.to_f > 0 conn = conn_for(u, verify, cert, timeout) return @fallback.send_once(meth, url, hdrs, body, timeout, proxies, verify, cert, auth) if conn == :http1 end end end |
#stream_to(meth, url, hdrs, body, timeout, proxies, verify, cert, auth, io, chunk_size: 65_536, progress: nil) ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/requests/http2.rb', line 341 def stream_to(meth, url, hdrs, body, timeout, proxies, verify, cert, auth, io, chunk_size: 65_536, progress: nil) u = URI.parse(url) sync_fallback! unless usable?(u, proxies) return @fallback.stream_to(meth, url, hdrs, body, timeout, proxies, verify, cert, auth, io, chunk_size: chunk_size, progress: progress) end conn = conn_for(u, verify, cert, timeout) if conn == :http1 return @fallback.stream_to(meth, url, hdrs, body, timeout, proxies, verify, cert, auth, io, chunk_size: chunk_size, progress: progress) end auth.call(hdrs) if auth.respond_to?(:call) && !auth.is_a?(Requests::DigestAuth) begin header_list = build_headers(meth, u, hdrs) _open_t, read_t = split_timeout(timeout) with_timeout(read_t) { conn.request(meth, u, header_list, body, io: io, progress: progress) } rescue Requests::ConnectionError, Requests::ConnectTimeout => e drop_conn(u) raise e end end |