RestClient Proxy Configuration

← Back to Ruby Libraries

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 proxy
  • X-ProxyMesh-IP - Request a specific outgoing IP address
  • X-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

Related Ruby Proxy Guides

Explore proxy configuration for other Ruby HTTP libraries:

Start Free Trial