Module: RubyProxyHeaders::NetHTTP

Defined in:
lib/ruby_proxy_headers/net_http.rb

Overview

Patches Net::HTTP#connect for HTTPS-over-proxy so extra headers can be sent on the CONNECT request and response headers can be read (e.g. ProxyMesh X-ProxyMesh-IP). Based on the same tunnel flow as Python's http.client / urllib3 extensions in python-proxy-headers.

Examples:

require 'ruby_proxy_headers/net_http'
RubyProxyHeaders::NetHTTP.patch!

http = Net::HTTP.new(uri.host, uri.port, proxy.host, proxy.port, proxy.user, proxy.password)
http.use_ssl = true
http.proxy_connect_request_headers = { 'X-ProxyMesh-IP' => '203.0.113.1' }
res = http.request(Net::HTTP::Get.new(uri))
p http.last_proxy_connect_response_headers

Defined Under Namespace

Modules: Extension

Constant Summary collapse

ORIGINAL_CONNECT =
::Net::HTTP.instance_method(:connect)

Class Method Summary collapse

Class Method Details

.patch!Object



160
161
162
163
164
165
# File 'lib/ruby_proxy_headers/net_http.rb', line 160

def patch!
  return if @patched

  ::Net::HTTP.prepend(Extension)
  @patched = true
end

.patched?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/ruby_proxy_headers/net_http.rb', line 167

def patched?
  @patched == true
end