dialer

package
v1.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: Apache-2.0, BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package dialer provides proxy-aware dialers for plain TCP and TLS connections using environment variables.

Supported proxy environment variables (checked case-insensitively):

Precedence when multiple proxies are set (both for net and TLS dialers):

  1. SOCKS5_PROXY
  2. HTTPS_PROXY
  3. HTTP_PROXY

Both uppercase and lowercase variable names are honored.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaselineTLSConfig

func BaselineTLSConfig(skipVerify bool, secure bool) (*tls.Config, error)

func DialTCP

func DialTCP(ctx context.Context, address string, opts Opts) (net.Conn, error)

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

func DialTLS(ctx context.Context, address string, opts Opts) (*tls.Conn, error)

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

func NewHTTPClient(opts Opts) (*http.Client, error)

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

func StrictBaselineTLSConfig() *tls.Config

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

type Opts struct {
	Timeout   time.Duration
	TLSConfig *tls.Config
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL