Class: Zenrows::Backends::NetHttp

Inherits:
Base
  • Object
show all
Defined in:
lib/zenrows/backends/net_http.rb

Overview

Net::HTTP backend adapter (stdlib fallback)

Uses Ruby's built-in Net::HTTP when http.rb is not available. Provides basic proxy support with SSL verification disabled.

Examples:

Basic usage

backend = Zenrows::Backends::NetHttp.new(proxy: proxy, config: config)
http = backend.build_client(js_render: true)
response = http.get(url)

Author:

  • Ernest Bursa

Since:

  • 0.2.1

Instance Attribute Summary

Attributes inherited from Base

#config, #proxy

Instance Method Summary collapse

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 = {}) ⇒ NetHttpClient

Build a configured HTTP client wrapper

Parameters:

  • options (Hash) (defaults to: {})

    Request options

Returns:

Since:

  • 0.2.1



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/zenrows/backends/net_http.rb', line 27

def build_client(options = {})
  opts = options.dup
  headers = opts.delete(:headers) || {}
  opts[:custom_headers] = true if headers.any?

  proxy_config = proxy.build(opts)
  timeouts = calculate_timeouts(opts)

  NetHttpClient.new(
    proxy_config: proxy_config,
    headers: headers,
    timeouts: timeouts,
    ssl_context: ssl_context
  )
end