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)

Since:

  • 0.2.1

Instance Attribute Summary

Attributes inherited from Base

#config, #hooks, #proxy

Instance Method Summary collapse

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_nameSymbol

Returns Backend identifier.

Returns:

  • (Symbol)

    Backend identifier

Since:

  • 0.2.1



47
48
49
# File 'lib/zenrows/backends/net_http.rb', line 47

def backend_name
  :net_http
end

#build_client(options = {}) ⇒ NetHttpClient, InstrumentedClient

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
42
43
44
# 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)

  client = NetHttpClient.new(
    proxy_config: proxy_config,
    headers: headers,
    timeouts: timeouts,
    ssl_context: ssl_context
  )

  # Wrap with instrumentation if hooks registered
  wrap_client(client, opts)
end