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
-
#backend_name ⇒ Symbol
Backend identifier.
-
#build_client(options = {}) ⇒ HTTP::Client, InstrumentedClient
Build a configured HTTP client.
Methods inherited from Base
#calculate_timeouts, #initialize, #ssl_context, #wrap_client
Constructor Details
This class inherits a constructor from Zenrows::Backends::Base
Instance Method Details
#backend_name ⇒ Symbol
Returns Backend identifier.
61 62 63 |
# File 'lib/zenrows/backends/http_rb.rb', line 61 def backend_name :http_rb end |
#build_client(options = {}) ⇒ HTTP::Client, InstrumentedClient
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 56 57 58 |
# 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 client = 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 ) # Wrap with instrumentation if hooks registered wrap_client(client, opts) end |