Module: RubyProxyHeaders::ExconIntegration

Defined in:
lib/ruby_proxy_headers/excon.rb

Overview

Excon already supports extra CONNECT headers via +:ssl_proxy_headers+ (see Excon::SSLSocket). This module documents the mapping and a small helper.

Reading CONNECT response headers is not exposed on Excon's public response object for the origin request; use thread-local proxy_connect_response_headers only when the underlying transport is patched Net::HTTP, not Excon.

Class Method Summary collapse

Class Method Details

.get(url, proxy_url:, proxy_connect_headers: nil, **excon_opts) ⇒ Object

Parameters:

  • proxy_url (String)
  • proxy_connect_headers (Hash) (defaults to: nil)

    sent to the proxy during HTTPS CONNECT (Excon key: :ssl_proxy_headers)

  • excon_opts (Hash)

    merged into Excon.get / Excon.new options



22
23
24
25
26
27
28
29
# File 'lib/ruby_proxy_headers/excon.rb', line 22

def get(url, proxy_url:, proxy_connect_headers: nil, **excon_opts)
  opts = {
    proxy: normalize_proxy_url(proxy_url),
    ssl_proxy_headers: proxy_connect_headers,
    ssl_verify_peer: true
  }.merge(excon_opts)
  Excon.get(url, opts)
end

.normalize_proxy_url(proxy_url) ⇒ Object



31
32
33
34
35
36
# File 'lib/ruby_proxy_headers/excon.rb', line 31

def normalize_proxy_url(proxy_url)
  s = proxy_url.to_s.strip
  return s if s.match?(/\A[a-z][a-z0-9+\-.]*:\/\//i)

  "http://#{s}"
end