dial

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dial is the single path from an address to a connected socket, directly or through an HTTP or SOCKS5 proxy, and to a UDP socket for QUIC, directly or through a SOCKS5 UDP association. Every step honours the context and its deadline (decision 0010); no other package opens connections.

Index

Constants

View Source
const (
	SchemeHTTP    = "http"
	SchemeSOCKS5  = "socks5"
	SchemeSOCKS5H = "socks5h"
)

Supported proxy URL schemes.

View Source
const DefaultHTTP3ReadBufferSize = 1 << 20

DefaultHTTP3ReadBufferSize is the receive buffer a QUIC socket asks for by default: Chrome's (kQuicSocketReceiveBufferSize, net/quic/ quic_context.h, set on every QUIC socket it opens).

Variables

This section is empty.

Functions

func Credentials

func Credentials(p *url.URL) string

Credentials returns p's Basic Proxy-Authorization value, or "".

Types

type Dialer

type Dialer struct {
	// Timeout bounds the connect (through a proxy: to the proxy, and the
	// proxy's handshake), on top of the context's deadline.
	Timeout time.Duration
	// DialContext, when set, opens the connection (to the proxy, when
	// there is one) instead of net.Dialer; Timeout still bounds it.
	DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
	// Resolver looks host names up for net.Dialer; nil uses
	// net.DefaultResolver. DialContext does its own lookups.
	Resolver *net.Resolver
	// Proxy is how the profile's browser talks to proxies; nil (not
	// measured) makes proxies an error.
	Proxy *profile.Proxy
	// UserAgent is the profile's, which CONNECT requests carry.
	UserAgent string
	// BrowserAuth gives an HTTP proxy the URL's credentials as Proxy's
	// ConnectCredentials and ForwardCredentials say, after its 407.
	// Otherwise they go from the first request, placed as Proxy places
	// them unasked (ConnectAuth, ForwardAuth): only the proxy sees the
	// difference (decision 0039).
	BrowserAuth bool
	// HTTP3ReadBufferSize is the receive buffer a QUIC socket asks for
	// (SetReadBuffer; the OS may grant less): zero asks for
	// DefaultHTTP3ReadBufferSize, negative leaves the OS's default (see
	// setReadBuffer).
	HTTP3ReadBufferSize int
	// contains filtered or unexported fields
}

Dialer opens TCP connections, directly or through a proxy, and UDP sockets for QUIC. It is the one place connections start.

func (*Dialer) Challenged

func (d *Dialer) Challenged(p *url.URL, h http.Header) bool

Challenged records that p asked for credentials (a 407 with header h) on a plain-HTTP request, and reports whether they can be given: p has them and asks for Basic.

func (*Dialer) CheckProxy

func (d *Dialer) CheckProxy(p *url.URL) error

CheckProxy reports whether p is a proxy URL the dialer can use. The engine checks that the profile describes the proxy protocol.

func (*Dialer) Dial

func (d *Dialer) Dial(ctx context.Context, addr string) (net.Conn, error)

Dial connects to addr ("host:port"). It honours ctx's cancellation and deadline.

func (*Dialer) DialProxy

func (d *Dialer) DialProxy(ctx context.Context, p *url.URL) (net.Conn, error)

DialProxy connects to the proxy p itself, for plain-HTTP requests sent to it whole. A failure is a *ProxyError.

func (*Dialer) DialVia

func (d *Dialer) DialVia(ctx context.Context, p *url.URL, addr string) (net.Conn, error)

DialVia connects to addr through the proxy p: an HTTP proxy's CONNECT tunnel or a SOCKS5 connection, as the profile's browser asks for them. A failure before the tunnel is up is a *ProxyError.

func (*Dialer) Forget added in v0.2.0

func (d *Dialer) Forget(via string)

Forget drops what d has learned of the proxy whose URL is via (url.URL.String): that it asked for credentials, or refused a UDP association. It is then a proxy d has never used.

func (*Dialer) ForwardAuthorization

func (d *Dialer) ForwardAuthorization(p *url.URL) string

ForwardAuthorization returns the Proxy-Authorization a plain-HTTP request to p carries unasked, or "": p's credentials from the first request, or with BrowserAuth once p has asked or where the profile always sends them.

func (*Dialer) ListenUDP

func (d *Dialer) ListenUDP(ctx context.Context, host string, port uint16) (net.PacketConn, netip.AddrPort, error)

ListenUDP resolves host with Resolver and opens a UDP socket for a QUIC connection to its first address at port, returned with the socket. It honours ctx, bounded by Timeout. The socket asks for the receive buffer HTTP3ReadBufferSize says and keeps what the OS grants.

func (*Dialer) ListenUDPVia

func (d *Dialer) ListenUDPVia(ctx context.Context, p *url.URL, host string, port uint16) (net.PacketConn, netip.AddrPort, error)

ListenUDPVia opens a SOCKS5 UDP association through p (a socks5 or socks5h proxy) for a QUIC connection to host at port, and returns it with the peer address its datagrams are reported from: host's address when host is an IP address, else the unspecified IPv4 address (the proxy resolves the name, as for its TCP connections, and host never goes to Resolver). The association authenticates as DialVia does and lives as long as its control connection (proxy.Association). A failure is a *ProxyError; a refusal of UDP ASSOCIATE is remembered (UDPRefused). It honours ctx, bounded by Timeout; the socket asks for the receive buffer HTTP3ReadBufferSize says, as ListenUDP's does.

func (*Dialer) UDPRefused

func (d *Dialer) UDPRefused(p *url.URL) bool

UDPRefused reports whether p has refused a UDP association: its requests stay on TCP.

type ProxyError

type ProxyError struct {
	// Proxy is the proxy's URL, credentials included.
	Proxy *url.URL
	// StatusCode and Header are the proxy's answer, if any.
	StatusCode int
	Header     http.Header
	Err        error
}

ProxyError is a failure to reach a proxy or open a tunnel through it (connect, non-2xx CONNECT, SOCKS5 refusal, deadline). The root package turns it into mimicry.ProxyError.

func (*ProxyError) Error

func (e *ProxyError) Error() string

func (*ProxyError) Unwrap

func (e *ProxyError) Unwrap() error

Jump to

Keyboard shortcuts

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