HTTPClient Proxy Configuration
HTTPClient accepts a full proxy URL in the constructor. This follows proxy-examples/ruby/httpclient-proxy.rb. HTTPClient does not expose ProxyMesh-style CONNECT headers in the same way as patched Net::HTTP; for X-ProxyMesh-Country / X-ProxyMesh-IP over HTTPS, prefer Faraday or Net::HTTP with ruby-proxy-headers.
Installation
gem install httpclient
Add ruby-proxy-headers only if you also use a supported client for CONNECT headers.
Basic Proxy Configuration
require 'httpclient'
client = HTTPClient.new('http://username:password@proxyhost:31280')
response = client.get('https://api.ipify.org?format=json')
puts response.body
IP authentication
client = HTTPClient.new('http://proxyhost:port')
Custom Proxy Headers
For custom headers on HTTPS CONNECT, use Faraday with RubyProxyHeaders::FaradayIntegration or Net::HTTP with RubyProxyHeaders::NetHTTP.patch!. See the ruby-proxy-headers README.
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
- HTTPClient Documentation
- HTTPClient on RubyGems
- HTTPClient on RubyDoc
- ruby-proxy-headers (HTTPClient)
- 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: