HTTParty Proxy Configuration
HTTParty wraps Net::HTTP with a simple API. Set http_proxyaddr, http_proxyport, and optional credentials for ProxyMesh, as in proxy-examples/ruby/httparty-proxy.rb.
Installation
gem install httparty ruby-proxy-headers
Basic Proxy Configuration
require 'httparty'
require 'uri'
proxy = URI('http://username:password@proxyhost:31280')
response = HTTParty.get(
'https://api.ipify.org?format=json',
http_proxyaddr: proxy.host,
http_proxyport: proxy.port,
http_proxyuser: proxy.user,
http_proxypass: proxy.password
)
puts response.body
Custom Proxy Headers
require 'httparty'
require 'ruby_proxy_headers/httparty'
RubyProxyHeaders::NetHTTP.patch!
proxy = URI('http://username:password@proxyhost:31280')
HTTParty.get(
'https://api.ipify.org?format=json',
http_proxyaddr: proxy.host,
http_proxyport: proxy.port,
http_proxyuser: proxy.user,
http_proxypass: proxy.password,
proxy_connect_request_headers: { 'X-ProxyMesh-IP' => '203.0.113.1' },
connection_adapter: RubyProxyHeaders::ProxyHeadersConnectionAdapter
)
puts RubyProxyHeaders.proxy_connect_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
- HTTParty Documentation
- HTTParty on RubyGems
- HTTParty on RubyDoc
- ruby-proxy-headers (HTTParty)
- 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: