data HTTP::Proxy(https: URI?, http: URI?, no_proxy: Array[String])

The proxy a client goes through: an https target through a CONNECT tunnel, an http one by sending the request to the proxy in absolute form. The proxy URL's user information, if any, is sent as Proxy-Authorization: Basic.

proxy = HTTP::Proxy.new("http://proxy.example:3128", no_proxy: ["localhost", ".internal"])
proxy.proxy_for(URI.parse("https://example.com/")).to_s   # => "http://proxy.example:3128"
proxy.proxy_for(URI.parse("http://db.internal/"))         # => nil

<std:http>:1956

Class methods

def self.new(url: String | URI, *, no_proxy: Array[String] = …) -> HTTP::Proxy

One proxy for both schemes. Raises ArgumentError when url is not an http URL with a host.

<std:http>:1968

def self.new(*, https: URI?, http: URI?, no_proxy: Array[String] = …) -> HTTP::Proxy

A proxy for each scheme, nil for none.

<std:http>:1976

def self.from_env -> HTTP::Proxy?

The proxies of the environment: https_proxy for https targets and http_proxy for http ones, no_proxy for the hosts reached directly (each name in lower case first, then in upper case); nil when neither proxy is set. A URL without a scheme is taken as http://; one that is not an http URL with a host (socks5://) is ignored, with a warning on STDERR (once). As Go does, HTTP_PROXY is ignored when REQUEST_METHOD is set: in a CGI program, a request's Proxy header sets it (httpoxy).

<std:http>:1990

Methods

def https -> URI?

The proxy for https targets, nil for none.

<std:http>:1958

def http -> URI?

The proxy for http targets, nil for none.

<std:http>:1960

def no_proxy -> Array[String]

The hosts reached directly, as curl reads NO_PROXY: a host, a domain (example.com or .example.com: it and its subdomains), a host:port, or * for every host.

<std:http>:1964

def to_h -> Hash[Symbol, Object]

The fields as a Hash, by name.

<std:http>:1968

def proxy_for(target: URI) -> URI?

The proxy for target, nil when it is reached directly.

<std:http>:2040

def direct?(target: URI) -> Bool

Whether target is in no_proxy.

<std:http>:2047