iyi

Standard library, 0.18.0

std/http_proxy

The proxy the environment names for a URL: HTTPProxy.from_env(url), for HTTP.open's and HTTPClient.new's proxy.

import std/http_proxy to use it. Source: src/std/http_proxy.iyi at v0.18.0.

proxy = HTTPProxy.from_env(url)
HTTP.request("GET", url, proxy: proxy)

It reads http_proxy, https_proxy and no_proxy, and their names in capitals, and hands them to HTTP.proxy_for, which holds the rules - which variable a scheme takes, NO_PROXY's domains, suffixes, *, addresses, CIDR ranges and ports, and that localhost and a loopback address never go through a proxy - as Go's httpproxy has them. The rules are std/http's and pure; reading the environment is this module's alone, so std/http itself reaches no environment, and a program that wants none of it never imports this.

**Which name wins.** The name in lower case, when it is set, even to nothing: http_proxy= beside HTTP_PROXY=http://p:3128 means no proxy. This is Python's urllib.request.getproxies_environment; curl too reads the lower-case name first (and http_proxy in no other case at all), while Go reads the capitals first, and an empty value as unset. The gate holds the reading to Python's, case by case.

**HTTP_PROXY under CGI** (httpoxy, CVE-2016-1000110): a CGI server hands a request's Proxy: header to its script as HTTP_PROXY, so where REQUEST_METHOD is set - a CGI script's environment - the name in capitals is not read for http://, and the lower-case name still is, as Python does. (Go refuses either name there, with an error.) On Windows a variable's name has no case - http_proxy is HTTP_PROXY - so under CGI neither is read there: the lower-case name answered the request's own Proxy: header, which is the hole the rule closes. Python's reading on Windows comes to the same.

What it reaches: std/http's reach, and the process environment.

HTTPProxystruct

std/http_proxyiyi doc src/std/http_proxy.iyi
pub struct HTTPProxy
  # Whether a variable's name has no case here: Windows'.
  protected def self.folded? : Bool
  # The proxy *url* goes through under the environment, ready for `open`'s
  # *proxy*; nil when it goes direct.
  def self.from_env(url : String) : String | ::Nil
  def initialize
end