HTTP.rb Proxy Configuration
The http gem (HTTP.rb) supports proxies through HTTP.via(host, port, user, password), as in proxy-examples/ruby/http-rb-proxy.rb. For custom CONNECT headers over HTTPS, use RubyProxyHeaders::HTTPGem.
Installation
gem install http ruby-proxy-headers
Basic Proxy Configuration
require 'http'
require 'uri'
proxy = URI('http://username:password@proxyhost:31280')
response = HTTP.via(proxy.host, proxy.port, proxy.user, proxy.password)
.get('https://api.ipify.org?format=json')
puts response.to_s
Custom Proxy Headers
require 'ruby_proxy_headers/http_gem'
client = RubyProxyHeaders::HTTPGem.create_client(
proxy: 'http://username:password@proxyhost:31280',
proxy_headers: { 'X-ProxyMesh-Country' => 'US' }
)
response = client.get('https://api.ipify.org?format=json')
puts response.body
puts client.last_proxy_response_headers['X-ProxyMesh-IP']
ProxyMesh Headers Reference
Send these headers to control proxy behavior:
X-ProxyMesh-Country- Route through a specific country (e.g., "US"). Only works with world proxy or open proxyX-ProxyMesh-IP- Request a specific outgoing IP addressX-ProxyMesh-Not-IP- Exclude specific IPs from rotation
The proxy returns X-ProxyMesh-IP with the IP address used for the request (when your stack exposes CONNECT response headers).
Resources
- HTTP.rb Documentation
- HTTP.rb on RubyGems
- HTTP.rb on RubyDoc
- ruby-proxy-headers (HTTP.rb)
- ruby-proxy-headers on RubyGems
- ruby-proxy-headers on RubyDoc
- ProxyMesh Headers Reference
- Example Code on GitHub
Related Ruby Proxy Guides
Explore proxy configuration for other Ruby HTTP libraries: