Ruby Proxy Server Integration Guide
Ruby is widely used for web scraping, API clients, and automation. Whether you use Faraday, Net::HTTP, HTTParty, or Typhoeus, routing traffic through a rotating proxy helps avoid IP bans and rate limits.
ProxyMesh provides rotating HTTP proxies compatible with standard Ruby clients. The ruby-proxy-headers gem adds support for custom proxy headers (for example X-ProxyMesh-Country and reading X-ProxyMesh-IP) during HTTPS CONNECT tunneling where the underlying stack allows it.
Quick Start: Ruby Proxy Setup
Get started with ProxyMesh in three steps:
- Sign up for a free ProxyMesh trial to get your proxy credentials
- Install your HTTP library (and
ruby-proxy-headersif you need custom CONNECT headers) - Configure the proxy URL with your ProxyMesh server address
Basic Example with Faraday
require 'faraday'
proxy_url = 'http://username:password@proxyhost:31280'
conn = Faraday.new(proxy: proxy_url) do |f|
f.adapter Faraday.default_adapter
end
response = conn.get('https://api.ipify.org?format=json')
puts response.body
Each request through ProxyMesh can use a different IP address from the rotating pool.
With Environment Variables
Many tools respect HTTP_PROXY / HTTPS_PROXY:
export HTTPS_PROXY="http://username:password@proxyhost:31280"
Ruby HTTP Libraries with Proxy Support
ProxyMesh works with common Ruby HTTP clients. Runnable examples live in the proxy-examples repository.
Net::HTTP
Ruby standard library HTTP client. Use ruby_proxy_headers/net_http to send custom CONNECT headers and read proxy response headers.
gem install ruby-proxy-headers (stdlib included)
Faraday
Popular HTTP client abstraction with adapters. RubyProxyHeaders::FaradayIntegration merges CONNECT response headers into Faraday responses.
gem install faraday faraday-net_http ruby-proxy-headers
HTTParty
Simple DSL on top of Net::HTTP. Pair with RubyProxyHeaders::NetHTTP.patch! and ProxyHeadersConnectionAdapter for CONNECT headers.
gem install httparty ruby-proxy-headers
Excon
Fast client with :ssl_proxy_headers for sending headers on CONNECT. RubyProxyHeaders::ExconIntegration documents the mapping.
gem install excon ruby-proxy-headers
HTTP.rb
The http gem with HTTP.via for proxies. RubyProxyHeaders::HTTPGem helps with HTTPS and custom CONNECT headers.
gem install http ruby-proxy-headers
Typhoeus
libcurl bindings for Ruby. Use :proxy for basic proxying; RubyProxyHeaders::Typhoeus for HTTPS with custom CONNECT headers.
gem install typhoeus ruby-proxy-headers
RestClient
Simple REST client. Set RestClient.proxy for basic use; RubyProxyHeaders::RestClient for HTTPS with proxy headers.
gem install rest-client ruby-proxy-headers
HTTPClient
Feature-rich client with HTTPClient.new(proxy_url). For CONNECT headers over HTTPS, prefer Faraday or patched Net::HTTP.
gem install httpclient
Mechanize
Browser-like automation with set_proxy. For advanced CONNECT headers, combine with Net::HTTP + ruby-proxy-headers or Faraday.
gem install mechanize
Nokogiri
HTML/XML parsing. Fetch through a proxy with Net::HTTP (or another client), then parse with Nokogiri.
gem install nokogiri
Why Use ProxyMesh for Ruby Web Scraping?
Automatic IP Rotation
Every request through ProxyMesh can use a different IP address from our rotating pool. Each location maintains multiple IPs that rotate throughout the day, giving you access to hundreds of unique addresses without code changes. This automatic rotation helps you:
- Avoid IP bans when scraping websites
- Bypass rate limiting based on IP address
- Distribute requests for better anonymity
Multiple Geographic Locations
ProxyMesh operates proxy servers worldwide in 17 locations:
- Los Angeles, CA, US
- Seattle, WA, US
- Paris, France
- Tokyo, Japan
- Sydney, Australia
- Frankfurt, Germany
- Amsterdam, Netherlands
- Singapore
- Chicago, IL, US
- Dallas, TX, US
- Washington DC, US
- New York, NY, US
- London, UK
- Zurich, Switzerland
- Orlando, FL, US
- Mumbai, India
- Open Proxy Server
- World Proxy Server
- US ISP Proxy Server
Access geo-restricted content or test how your application appears from different regions by connecting to the appropriate proxy location.
Simple Authentication
ProxyMesh supports two authentication methods:
- Username/Password: Include credentials in the proxy URL:
http://username:password@proxyhost:31280 - IP Authentication: Whitelist your server's IP in the dashboard—no credentials needed in code
Custom headers over HTTPS
The ruby-proxy-headers gem (RubyDoc) integrates with Net::HTTP, Faraday, HTTParty, Excon, and more. See the GitHub README for details.
Advanced: Custom Proxy Headers
ProxyMesh supports headers such as X-ProxyMesh-Country, X-ProxyMesh-IP, and X-ProxyMesh-Not-IP. Sending them on HTTPS requires attaching them to the proxy CONNECT request—handled by ruby-proxy-headers for supported stacks.
- ruby-proxy-headers on RubyGems
- ruby-proxy-headers on RubyDoc
- ruby-proxy-headers on GitHub
- ProxyMesh headers documentation
Documentation and Resources
ProxyMesh Documentation
- HTTP Proxy Configuration Guide
- Proxy Server Locations
- Proxy Authentication Options
- Custom Headers Reference
Packages and Examples
- RubyGems.org (gem index) and RubyDoc.info (gem API docs)—each library guide below links to its gem and RubyDoc where applicable.
- ruby-proxy-headers on RubyGems
- ruby-proxy-headers on RubyDoc
- ruby-proxy-headers on GitHub
- Ruby proxy-examples on GitHub
Frequently Asked Questions
What is the best Ruby HTTP library for proxy requests?
Faraday is a flexible choice for most applications. Net::HTTP is built into Ruby. HTTParty offers a simple API. Typhoeus suits libcurl workloads. Use ruby-proxy-headers when you need custom CONNECT headers over HTTPS.
How do I configure a rotating proxy in Ruby?
Configure your client with a ProxyMesh proxy URL such as http://username:password@proxyhost:31280. ProxyMesh rotates IPs automatically.
Does ProxyMesh work with Ruby on Rails?
Yes. Use the same proxy URL with Faraday, Net::HTTP, or other outbound clients. For HTTPS CONNECT headers, use ruby-proxy-headers with Faraday or patched Net::HTTP.
Where can I install ruby-proxy-headers?
Run gem install ruby-proxy-headers or add gem 'ruby-proxy-headers' to your Gemfile. Documentation: GitHub, RubyGems, and RubyDoc.