Documentation
¶
Overview ¶
Package dialer provides proxy-aware dialers for plain TCP and TLS connections using environment variables.
Supported proxy environment variables (checked case-insensitively):
- SOCKS5_PROXY (e.g., socks5://user:pass@host:1080)
- HTTPS_PROXY (e.g., https://user:pass@host:443)
- HTTP_PROXY (e.g., http://user:pass@host:3128)
Precedence when multiple proxies are set (both for net and TLS dialers):
- SOCKS5_PROXY
- HTTPS_PROXY
- HTTP_PROXY
Both uppercase and lowercase variable names are honored.
Index ¶
- func BaselineTLSConfig(skipVerify bool, secure bool) (*tls.Config, error)
- func DialTCP(ctx context.Context, address string, opts Opts) (net.Conn, error)
- func DialTLS(ctx context.Context, address string, opts Opts) (*tls.Conn, error)
- func NewHTTPClient(opts Opts) (*http.Client, error)
- func StrictBaselineTLSConfig() *tls.Config
- func StrictTLSFlag(useStrict *bool)
- type ContextDialer
- type Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DialTCP ¶
DialTCP is a convenience helper that dials a TCP connection to address using a proxy-aware dialer derived from opts. It honors SOCKS5_PROXY, HTTPS_PROXY, and HTTP_PROXY environment variables.
func DialTLS ¶
DialTLS is a convenience helper that dials a TLS-wrapped TCP connection to address using a proxy-aware dialer derived from opts. It returns a *tls.Conn. It honors SOCKS5_PROXY, HTTPS_PROXY, and HTTP_PROXY environment variables and uses opts.TLSConfig for the handshake (filling ServerName from address if empty).
func NewHTTPClient ¶
NewHTTPClient returns an *http.Client that is proxy-aware.
Behavior:
- If SOCKS5_PROXY is set, the client routes all TCP connections through the SOCKS5 proxy using a custom DialContext, and disables HTTP(S) proxying in the transport (per our precedence SOCKS5 > HTTPS > HTTP).
- Otherwise, it uses http.ProxyFromEnvironment which supports HTTP_PROXY, HTTPS_PROXY, and NO_PROXY/no_proxy.
- Connection and TLS handshake timeouts are derived from opts.Timeout.
- For HTTPS targets, opts.TLSConfig is applied to the transport.
func StrictBaselineTLSConfig ¶
StrictBaselineTLSConfig returns a secure TLS config. Many of the tools in this repo are designed to debug broken TLS systems and therefore explicitly support old or insecure TLS setups.
func StrictTLSFlag ¶
func StrictTLSFlag(useStrict *bool)
Types ¶
type ContextDialer ¶
type ContextDialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
ContextDialer matches the common DialContext signature used by net and tls dialers.
func NewNetDialer ¶
func NewNetDialer(opts Opts) (ContextDialer, error)
NewNetDialer returns a ContextDialer that dials TCP connections using proxies discovered from the environment (SOCKS5_PROXY, HTTPS_PROXY, HTTP_PROXY). The returned dialer supports context cancellation for direct and HTTP(S) proxies and applies the configured timeout to connection/proxy handshake.
func NewTLSDialer ¶
func NewTLSDialer(opts Opts) (ContextDialer, error)
NewTLSDialer returns a ContextDialer that establishes a TLS connection to the destination, while honoring SOCKS5_PROXY/HTTPS_PROXY/HTTP_PROXY.
The returned dialer performs proxy negotiation (if any), then completes a TLS handshake to the target using opts.TLSConfig.
type Opts ¶ added in v1.15.1
Opts controls creation of proxy-aware dialers.
Timeout controls the maximum amount of time spent establishing the underlying TCP connection and any proxy handshake. If zero, a reasonable default (30s) is used.
TLSConfig is used by the TLS dialer to configure the TLS handshake to the target endpoint. If TLSConfig.ServerName is empty, it will be set from the host portion of the address passed to DialContext.