ProxyHTTP Proxy Configuration
Per RFC 9110 Section 3.7 and Section 7.3.2: A proxy is a message-forwarding agent chosen by the client, usually configured via local rules.
Create a proxy configuration:
let proxy = Proxy.http ~port:8080 "proxy.example.com"
(* With authentication *)
let proxy = Proxy.http
~port:8080
~auth:(Auth.basic ~username:"user" ~password:"pass")
"proxy.example.com"
(* With bypass list *)
let proxy = Proxy.http
~no_proxy:["localhost"; "*.internal.example.com"]
"proxy.example.com"Read from environment variables:
match Proxy.from_env () with
| Some proxy -> (* use proxy *)
| None -> (* no proxy configured *)val src : Logs.Src.tLog source for proxy operations
type config = {host : string;Proxy server hostname
*)port : int;Proxy server port (default: 8080)
*)proxy_type : proxy_type;auth : Auth.t option;Proxy authentication (Proxy-Authorization)
*)no_proxy : string list;Hosts/patterns to bypass proxy
*)}Proxy configuration
http ?port ?auth ?no_proxy host creates an HTTP proxy configuration.
socks5 ?port ?auth ?no_proxy host creates a SOCKS5 proxy configuration.
Note: SOCKS5 support is not yet implemented. This function creates the configuration type for future use.
val should_bypass : config -> string -> boolshould_bypass config url returns true if url should bypass the proxy based on the no_proxy list.
Matching rules:
*.example.com matches foo.example.comlocalhost and 127.0.0.1 match by default if in no_proxy listval host_port : config -> string * inthost_port config returns the proxy host and port as a tuple.
val validate_supported : config -> unitvalidate_supported config checks that the proxy type is currently supported.
val from_env : unit -> config optionfrom_env () reads proxy configuration from environment variables.
Checks the following variables (in order of preference):
HTTP_PROXY / http_proxyHTTPS_PROXY / https_proxyALL_PROXY / all_proxyNO_PROXY / no_proxy (comma-separated list of bypass patterns)Returns None if no proxy is configured.
URL format: http://[user:pass@]host[:port]
Example environment:
HTTP_PROXY=http://user:pass@proxy.example.com:8080
NO_PROXY=localhost,*.internal.example.com,.example.orgval from_env_for_url : string -> config optionfrom_env_for_url url reads proxy configuration appropriate for url.
HTTPS_PROXY for HTTPS URLsHTTP_PROXY for HTTP URLsALL_PROXYNone if the URL matches NO_PROXY patternsval pp_proxy_type : Format.formatter -> proxy_type -> unitPretty printer for proxy type
val pp_config : Format.formatter -> config -> unitPretty printer for proxy configuration. Note: Authentication credentials are redacted.