package fasthttpproxy

import "github.com/valyala/fasthttp/fasthttpproxy"

Index

Functions

func FasthttpHTTPDialer

func FasthttpHTTPDialer(proxy string) fasthttp.DialFunc

FasthttpHTTPDialer returns a fasthttp.DialFunc that dials using the provided HTTP proxy.

Example usage:

c := &fasthttp.Client{
	Dial: fasthttpproxy.FasthttpHTTPDialer("username:password@localhost:9050"),
}

func FasthttpHTTPDialerTimeout

func FasthttpHTTPDialerTimeout(proxy string, timeout time.Duration) fasthttp.DialFunc

FasthttpHTTPDialerTimeout returns a fasthttp.DialFunc that dials using the provided HTTP proxy using the given timeout. The timeout parameter determines both the dial timeout and the CONNECT request timeout.

Example usage:

c := &fasthttp.Client{
	Dial: fasthttpproxy.FasthttpHTTPDialerTimeout("username:password@localhost:9050", time.Second * 2),
}

func FasthttpProxyHTTPDialer

func FasthttpProxyHTTPDialer() fasthttp.DialFunc

FasthttpProxyHTTPDialer returns a fasthttp.DialFunc that dials using the env(HTTP_PROXY, HTTPS_PROXY and NO_PROXY) configured HTTP proxy.

Example usage:

c := &fasthttp.Client{
	Dial: fasthttpproxy.FasthttpProxyHTTPDialer(),
}

func FasthttpProxyHTTPDialerTimeout

func FasthttpProxyHTTPDialerTimeout(timeout time.Duration) fasthttp.DialFunc

FasthttpProxyHTTPDialerTimeout returns a fasthttp.DialFunc that dials using the env(HTTP_PROXY, HTTPS_PROXY and NO_PROXY) configured HTTP proxy using the given timeout. The timeout parameter determines both the dial timeout and the CONNECT request timeout.

Example usage:

c := &fasthttp.Client{
	Dial: fasthttpproxy.FasthttpProxyHTTPDialerTimeout(time.Second * 2),
}

func FasthttpSocksDialer

func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc

FasthttpSocksDialer returns a fasthttp.DialFunc that dials using the provided SOCKS5 proxy.

Example usage:

c := &fasthttp.Client{
	Dial: fasthttpproxy.FasthttpSocksDialer("socks5://localhost:9050"),
}

Types

type Dialer

type Dialer struct {
	fasthttp.TCPDialer
	// Support HTTPProxy, HTTPSProxy and NoProxy configuration.
	//
	// HTTPProxy represents the value of the HTTP_PROXY or
	// http_proxy environment variable. It will be used as the proxy
	// URL for HTTP requests unless overridden by NoProxy.
	//
	// HTTPSProxy represents the HTTPS_PROXY or https_proxy
	// environment variable. It will be used as the proxy URL for
	// HTTPS requests unless overridden by NoProxy.
	//
	// NoProxy represents the NO_PROXY or no_proxy environment
	// variable. It specifies a string that contains comma-separated values
	// specifying hosts that should be excluded from proxying. Each value is
	// represented by an IP address prefix (1.2.3.4), an IP address prefix in
	// CIDR notation (1.2.3.4/8), a domain name, or a special DNS label (*).
	// An IP address prefix and domain name can also include a literal port
	// number (1.2.3.4:80).
	// A domain name matches that name and all subdomains. A domain name with
	// a leading "." matches subdomains only. For example "foo.com" matches
	// "foo.com" and "bar.foo.com"; ".y.com" matches "x.y.com" but not "y.com".
	// A single asterisk (*) indicates that no proxying should be done.
	// A best effort is made to parse the string and errors are
	// ignored.
	httpproxy.Config
	// Attempt to connect to both ipv4 and ipv6 addresses if set to true.
	// By default, dial only to ipv4 addresses,
	// since unfortunately ipv6 remains broken in many networks worldwide :)
	//
	// This field from the fasthttp client is provided redundantly here because
	// when we customize the Dial function for the client, its DialDualStack field
	// configuration becomes ineffective.
	DialDualStack bool
	// Dial timeout.
	//
	// This field from the fasthttp client is provided redundantly here because
	// when we customize the Dial function for the client, its DialTimeout field
	// configuration becomes ineffective.
	Timeout time.Duration
	// The timeout for sending a CONNECT request when using an HTTP proxy.
	ConnectTimeout time.Duration
}

Dialer embeds both fasthttp.TCPDialer and httpproxy.Config, allowing it to take advantage of the optimizations provided by fasthttp for dialing while also utilizing the finer-grained configuration options offered by httpproxy.

func (*Dialer) Dial

func (d *Dialer) Dial(network, addr string) (conn net.Conn, err error)

Dial is solely for implementing the proxy.Dialer interface.

func (*Dialer) GetDialFunc

func (d *Dialer) GetDialFunc(useEnv bool) (dialFunc fasthttp.DialFunc, err error)

GetDialFunc method returns a fasthttp-style dial function. The useEnv parameter determines whether the proxy address comes from Dialer.Config or from environment variables.

type DialerFunc

type DialerFunc func(network, addr string) (net.Conn, error)

DialerFunc Make a function of type func(network, addr string) (net.Conn, error) implement the proxy.Dialer interface.

func (DialerFunc) Dial

func (d DialerFunc) Dial(network, addr string) (net.Conn, error)

Source Files

dialer.go http.go proxy_env.go socks5.go

Version
v1.56.0
Published
Sep 22, 2024
Platform
js/wasm
Imports
12 packages
Last checked
3 weeks ago

Tools for package owners.