Documentation
¶
Overview ¶
Package proxykit provides a small, dependency-light client for outbound connections through HTTP CONNECT and SOCKS5 proxies, with optional system-proxy auto-detection and pluggable authentication (Basic, NTLM, Negotiate/SSPI on Windows).
The package exposes a Dialer that satisfies the standard net.Dial signature, plus an http.RoundTripper adapter for use with http.Client.
Quickstart ¶
cfg := proxykit.Config{Manual: "http://proxy:8080"}
d := proxykit.NewDialer(cfg)
conn, err := d.DialContext(ctx, "tcp", "example.com:443")
See the examples directory for more usage patterns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHTTPTransport ¶
func NewHTTPTransport(cfg Config) http.RoundTripper
NewHTTPTransport returns an http.RoundTripper that dials through the proxy chain configured by cfg. It is a thin wrapper over http.Transport with DialContext set to the result of NewDialer; callers who need additional knobs (TLS config, idle pool sizing, HTTP/2 toggle) should construct their own *http.Transport using NewDialer directly.
func ParseProxyURL ¶
ParseProxyURL parses a proxy address into a *url.URL.
It accepts URLs with scheme http, https, socks, or socks5, plus bare "host:port" or "host" (treated as http on the default port).
The returned URL always has Host populated with an explicit port. Default ports per scheme: http=80, https=443, socks/socks5=1080.
Unsupported schemes (socks4, socks4a, ftp, ...) and empty input return an error.
Types ¶
type Config ¶
type Config struct {
// Manual is an explicit proxy URL such as "http://proxy:8080" or
// "socks5://1.2.3.4:1080". When set, it takes precedence over
// AutoDetect. Empty means no manual override.
Manual string
// AutoDetect enables system proxy detection (environment variables,
// Windows WinINET registry). Consulted only if Manual is empty.
AutoDetect bool
// Auth is the ordered list of Authenticators tried on HTTP 407
// from a CONNECT proxy. The transport matches each Authenticator's
// Scheme against the proxy-advertised Proxy-Authenticate values.
Auth []auth.Authenticator
// Timeout bounds a single dial attempt to the proxy or destination.
// Zero means no timeout.
Timeout time.Duration
// OnLog, when non-nil, receives diagnostic messages. The level is
// one of "debug", "info", "warn", "error".
OnLog func(level, msg string)
}
Config configures a proxy Dialer or HTTP transport.
type Dialer ¶
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer establishes outbound TCP connections, optionally through a proxy. The DialContext signature matches net.Dialer.DialContext so the result drops into http.Transport unchanged.
func NewDialer ¶
NewDialer returns a Dialer wired according to cfg.
Resolution order:
- cfg.Manual (when non-empty) is tried first.
- cfg.AutoDetect runs every registered detector (env vars, WinINET on Windows) and appends each candidate.
For each resolved proxy URL a transport is selected by scheme (http/https → CONNECT, socks/socks5 → SOCKS5). Userinfo embedded in the URL is converted into either an auth.Basic prepended to cfg.Auth (CONNECT proxies) or RFC 1929 SOCKS authentication.
When several candidates resolve, dial attempts walk the chain in order and return the first success — preserving the precedence model in reverse_ssh. With no usable proxy the Dialer falls back to a direct net.Dialer with cfg.Timeout.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides Authenticator implementations for HTTP CONNECT proxy authentication.
|
Package auth provides Authenticator implementations for HTTP CONNECT proxy authentication. |
|
cmd
|
|
|
proxytest
command
Command proxytest is a diagnostic CLI for proxykit.
|
Command proxytest is a diagnostic CLI for proxykit. |
|
Package detect discovers system proxy configurations from one or more sources (environment variables, the Windows WinINET registry, etc.) and exposes them as a uniform list of [Candidate]s.
|
Package detect discovers system proxy configurations from one or more sources (environment variables, the Windows WinINET registry, etc.) and exposes them as a uniform list of [Candidate]s. |
|
examples
|
|
|
autodetect
command
Command autodetect dials through a system-detected proxy.
|
Command autodetect dials through a system-detected proxy. |
|
basic
command
Command basic dials a destination through an explicit proxy URL.
|
Command basic dials a destination through an explicit proxy URL. |
|
http_client
command
Command http_client demonstrates plugging proxykit into the stdlib http.Client as a custom transport.
|
Command http_client demonstrates plugging proxykit into the stdlib http.Client as a custom transport. |
|
Package transport contains concrete dial implementations selected by the top-level [proxykit.Dialer].
|
Package transport contains concrete dial implementations selected by the top-level [proxykit.Dialer]. |