RestClient Proxy Configuration
RestClient supports a global RestClient.proxy URL. This matches proxy-examples/ruby/rest-client-proxy.rb. For HTTPS with custom proxy headers, use RubyProxyHeaders::RestClient.
Installation
gem install rest-client ruby-proxy-headers
Basic Proxy Configuration
require 'rest-client'
RestClient.proxy = 'http://username:password@proxyhost:31280'
response = RestClient.get('https://api.ipify.org?format=json')
puts response.body
Custom Proxy Headers
require 'ruby_proxy_headers/rest_client'
response = RubyProxyHeaders::RestClient.get(
'https://api.ipify.org?format=json',
proxy: 'http://username:password@proxyhost:31280',
proxy_headers: { 'X-ProxyMesh-Country' => 'US' }
)
puts response.body
puts response.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
- RestClient Documentation
- RestClient on RubyGems
- RestClient on RubyDoc
- ruby-proxy-headers (RestClient)
- 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: