fasthttpproxy

package
v0.0.0-...-9759ddc Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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

	// 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
	// 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
}

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) DialTimeout

func (d *Dialer) DialTimeout(network, addr string, timeout time.Duration) (conn net.Conn, err error)

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.

func (*Dialer) GetDialTimeoutFunc

func (d *Dialer) GetDialTimeoutFunc(useEnv bool) (dialFunc TimeoutDial, err error)

GetDialTimeoutFunc 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)

type DialerV2

type DialerV2 struct {
	Dialer
	UseEnv bool
	// contains filtered or unexported fields
}

func (*DialerV2) Dial

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

func (*DialerV2) DialTimeout

func (d *DialerV2) DialTimeout(network, addr string, timeout time.Duration) (net.Conn, error)

type TimeoutDial

type TimeoutDial func(network, addr string, timeout time.Duration) (con net.Conn, err error)

func (TimeoutDial) Dial

func (t TimeoutDial) Dial(network, addr string) (con net.Conn, err error)

func (TimeoutDial) DialTimeout

func (t TimeoutDial) DialTimeout(network, addr string, timeout time.Duration) (con net.Conn, err error)

Jump to

Keyboard shortcuts

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