ruby-proxy-headers 0.3.0 fixes HTTPS requests that send proxy headers through Typhoeus, HTTP.rb, and RestClient, which failed in 0.2.3. It also requires Ruby 3.2 or newer. If you run Ruby 3.2 or newer, upgrade. If you run Ruby 3.1, stay on 0.2.3.

gem install ruby-proxy-headers

In your Gemfile, use gem 'ruby-proxy-headers', '~> 0.3.0', then run bundle update ruby-proxy-headers. The gem doesn't install Typhoeus, Faraday, or the other clients, so you add the one you use.

Typhoeus, HTTP.rb, and RestClient requests now work

In 0.2.3, HTTPS requests with proxy headers through Typhoeus, HTTP.rb, and RestClient failed. They work in 0.3.0, and you don't need to change your code.

Typhoeus now sends your proxy headers and gives you the proxy's reply in proxy_response_headers, including X-ProxyMesh-IP. response.headers still holds the website's response. With HTTP.rb and RestClient, you read response.proxy_response_headers. This needs Typhoeus 1.7 or the http gem 6 or newer.

Net::HTTP uses your installed net-http settings

0.3.0 works with the timeouts and HTTPS proxy settings of the net-http you have installed, and you can still send extra CONNECT headers and read the proxy's reply. You still call RubyProxyHeaders::NetHTTP.patch! once before you create connections.

Ruby 3.2 or newer is required

0.3.0 needs Ruby 3.2 or newer. On Ruby 3.1, stay on 0.2.3 by pinning it in your Gemfile:

gem 'ruby-proxy-headers', '0.2.3'

Faraday works with current faraday-net_http

0.3.0 works with faraday-net_http 3.4 and 3.5, and you don't need to change your Faraday code. res.headers['X-ProxyMesh-IP'] still works.

Example: read the proxy IP with Typhoeus

Use Proxy Server Locations to find the host and port for PROXY_HOST:PORT.

require 'ruby_proxy_headers/typhoeus'

response = RubyProxyHeaders::Typhoeus.get(
  'https://api.ipify.org?format=json',
  proxy: 'http://USERNAME:PASSWORD@PROXY_HOST:PORT',
  proxy_headers: { 'X-ProxyMesh-Country' => 'US' }
)
puts response.proxy_response_headers['X-ProxyMesh-IP']

Look for the proxy IP in response.proxy_response_headers, not in response.headers. X-ProxyMesh-Country works only on the World and Open proxies, and the request and response headers article lists every header ProxyMesh accepts and returns. The Ruby proxy configuration examples cover the other clients.

Links: ruby-proxy-headers 0.3.0 on RubyGems, the GitHub release, the full diff from 0.2.3, the changelog, and the API docs on RubyDoc.