Proxy

The proxy plugin allows one to send HTTP requests through a proxy.

All examples will assume the fictitious 10.10.0.1:51432 address/port pair. Replace the examples with your own.

Options

After enabling the plugin, you can call a #proxy method, which can receive the following options:

  • :uri: the proxy URI (see examples below)
  • :username: proxy user (optional)
  • :password: proxy password (optional)

HTTP Proxy

Use an HTTP cache proxy to route clear-text HTTP requests.

HTTPX.plugin(:proxy).with_proxy(uri: "http://10.10.0.1:51432").get("http://dn.pt")

HTTPS Proxy

Use an HTTPS proxy to tunnel secure HTTP(S) requests.

HTTPX.plugin(:proxy).with_proxy(uri: "https://10.10.0.1:51432").get("https://google.pt")

Socks4/4a/5

Use an HTTPS proxy to tunnel secure HTTP(S) requests.

HTTPX.plugin(:proxy).with_proxy(uri: "socks4://10.10.0.1:51432").get("https://google.pt")
HTTPX.plugin(:proxy).with_proxy(uri: "socks4a://10.10.0.1:51432").get("https://google.pt")
HTTPX.plugin(:proxy).with_proxy(uri: "socks45://10.10.0.1:51432").get("https://google.pt")

SSH

This plugin creates an SSH connection (using the net-ssh-gateway gem) and tunnels all requests from the session through it.

session = HTTPX.plugin(:"proxy/ssh")
               .with_proxy(uri: "ssh://10.10.0.1:51432",
                           username: "root",
                           password: "root")
response = session.get("https://google.pt")

ENV http_proxy/https_proxy/no_proxy

If the proxy environment variables are defined, HTTPX will load with the plugin turned on by default. It will therefore route or not route the requests through a proxy based on those variables. Their declaration format is the same as the one used in the proxy :uri parameter.

Caveats

Because of the implicit sharing of known peer IP, HTTP/2 connection coalescing is disabled. HTTP/1.1 pipelining support may also be limited (most proxies don’t support it), so beware of its utilization.

Next: Authentication