Class: Zenrows::Backends::HttpRb
- Defined in:
- lib/zenrows/backends/http_rb.rb
Overview
HTTP.rb backend adapter
Uses the http.rb gem to build configured HTTP clients that route through the ZenRows proxy.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build_client(options = {}) ⇒ HTTP::Client
Build a configured HTTP client.
Methods inherited from Base
#calculate_timeouts, #initialize, #ssl_context
Constructor Details
This class inherits a constructor from Zenrows::Backends::Base
Instance Method Details
#build_client(options = {}) ⇒ HTTP::Client
Build a configured HTTP client
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zenrows/backends/http_rb.rb', line 31 def build_client( = {}) opts = .dup headers = opts.delete(:headers) || {} # Enable custom_headers if we have headers opts[:custom_headers] = true if headers.any? # Get proxy configuration proxy_config = proxy.build(opts) # Calculate timeouts timeouts = calculate_timeouts(opts) # Build HTTP client with SSL context and proxy HTTP .timeout(connect: timeouts[:connect], read: timeouts[:read]) .headers(headers) .via( proxy_config[:host], proxy_config[:port], proxy_config[:username], proxy_config[:password], ssl_context: ssl_context ) end |