HTTParty Proxy Configuration

← Back to Ruby Libraries

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 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