Module: RubyProxyHeaders::HTTPGem

Defined in:
lib/ruby_proxy_headers/http_gem.rb

Overview

HTTP.rb (http gem) integration for proxy headers support.

Examples:

client = RubyProxyHeaders::HTTPGem.create_client(
  proxy: 'http://user:pass@proxy:8080',
  proxy_headers: { 'X-ProxyMesh-Country' => 'US' }
)

response = client.get('https://example.com')
puts response.proxy_response_headers

Defined Under Namespace

Classes: ProxyClient

Class Method Summary collapse

Class Method Details

.create_client(proxy:, proxy_headers: {}, **options) ⇒ ProxyClient

Create an HTTP client with proxy header support.

Parameters:

  • proxy (String)

    Proxy URL

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

    Custom headers to send to proxy

  • options (Hash)

    Additional HTTP.rb options

Returns:



21
22
23
# File 'lib/ruby_proxy_headers/http_gem.rb', line 21

def self.create_client(proxy:, proxy_headers: {}, **options)
  ProxyClient.new(proxy: proxy, proxy_headers: proxy_headers, **options)
end

.get(url, proxy:, proxy_headers: {}, **options) ⇒ Object

Make a GET request with proxy headers.



26
27
28
# File 'lib/ruby_proxy_headers/http_gem.rb', line 26

def self.get(url, proxy:, proxy_headers: {}, **options)
  create_client(proxy: proxy, proxy_headers: proxy_headers).get(url, **options)
end

.post(url, proxy:, proxy_headers: {}, body: nil, **options) ⇒ Object

Make a POST request with proxy headers.



31
32
33
# File 'lib/ruby_proxy_headers/http_gem.rb', line 31

def self.post(url, proxy:, proxy_headers: {}, body: nil, **options)
  create_client(proxy: proxy, proxy_headers: proxy_headers).post(url, body: body, **options)
end