Go to file
rulingcom 1d9659309b Allow customizing User-Agent header (HTTP only). 2024-02-24 12:01:29 +08:00
bin Renamed project to ruby-proxifier and renamed gem to proxifier. 2011-07-19 16:11:35 -04:00
lib Allow customizing User-Agent header (HTTP only). 2024-02-24 12:01:29 +08:00
spec Fixes for Proxy creation from URL String and SOCKS5 authentication. Bump version number to 1.0.4. 2024-02-24 11:58:46 +08:00
.gitignore Initial version 2011-06-09 11:28:05 -04:00
Gemfile Initial version 2011-06-09 11:28:05 -04:00
LICENSE Initial version 2011-06-09 11:28:05 -04:00
README.md Update README.md 2014-06-11 08:03:52 -04:00
Rakefile Fixes for Proxy creation from URL String and SOCKS5 authentication. Bump version number to 1.0.4. 2024-02-24 11:58:46 +08:00
proxifier.gemspec Fixes for Proxy creation from URL String and SOCKS5 authentication. Bump version number to 1.0.4. 2024-02-24 11:58:46 +08:00

README.md

ruby-proxifier

Installing

gem install proxifier

Edge

git clone https://github.com/samuelkadolph/ruby-proxifier
cd ruby-proxifier && rake install

Rationale

This gem was created for 2 purposes.

First is to enable ruby programmers to use HTTP or SOCKS proxies interchangeably when using TCPSockets. Either manually with Proxifier::Proxy#open or by require "proxifier/env".

The second purpose is to use ruby code that doesn't use proxies for users that have to use proxies.
The pruby and pirb executables are simple wrappers for their respective ruby executables that support proxies from environment variables.

Usage

Executable Wrappers & Environment Variables

proxifier provides two executables: pruby and pirb. They are simple wrappers for your current ruby and irb executables that requires the "proxifier/env" script which installs hooks into TCPSocket which will use the proxy environment variables to proxy any TCPSocket.

The environment variables that proxifier will check are (in order of descending precedence):

Variable Name Alternatives Notes
proxy PROXY Requires the proxy scheme to be present.
socks_proxy SOCKS_PROXY
socks5_proxy
SOCKS5_PROXY
Implies the SOCKS5 proxy scheme.
socks4a_proxy SOCKS4A_PROXY Implies the SOCKS4A proxy scheme.
socks4_proxy PROXY Implies the SOCKS4 proxy scheme.
http_proxy HTTP_PROXY Implies the HTTP proxy scheme.

Ruby

require "proxifier/proxy"

proxy = Proxifier::Proxy("socks://localhost")
socket = proxy.open("www.google.com", 80)
socket << "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n"
socket.gets # => "HTTP/1.1 200 OK\r\n"

Supported Proxies

Protocol Formats Notes
HTTP
http://[username[:password]@]host[:port][?tunnel=false]
The port defaults to 80. This is currently a limitation that may be solved in the future.
Appending ?tunnel=false forces the proxy to not use CONNECT.
SOCKS5
socks://[username[:password]@]host[:port]
socks5://[username[:password]@]host[:port]
Port defaults to 1080.
SOCKS4A
socks4a://[username@]host[:port]
Not yet implemented.
SOCKS4
socks4://[username@]host[:port]
Currently hangs. Not sure if the problem is with code or server.