httpproxy

package
v0.0.0-...-84ddfae Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProxyFunc

func ProxyFunc(n *NoProxy, httpsProxy string) (func(*url.URL) (*url.URL, error), error)

func ValidateProxyURL

func ValidateProxyURL(proxyURL string) (*url.URL, error)

Types

type NoProxy

type NoProxy struct {
	// contains filtered or unexported fields
}

func ParseNoProxy

func ParseNoProxy(noProxyStr string) (*NoProxy, error)

ParseNoProxy parses values of NO_PROXY environment variables similar to how "http/httpproxy".FromEnvironment parses them, with the following differences:

  1. If the port of a host is empty (i.e. "example.com:") then an error is returned.
  2. If the port of a host is a named port (i.e. "example.com:http") then an error is returned.
  3. If the port of a host is not positive (i.e. "zeronotallowed.example.com:0") then an error is returned.
  4. If the hostname of a host has non-ASCII characters then an error is returned. A hostname must be normalized as per "golang.org/x/net/idna".Lookup.ToASCII (otherwise it never matches anything). NOTE: validation of hostnames can be stricter, however this level of strictness matches the "http/httpproxy" and "http" Golang packages (despite lower level code potentially being stricter).

This function always returns a non-nil *NoProxy and any error returned is suitable for printing in logs, but the error's Error() may return a string with line feeds. As such, this function is suitable for validation of the NO_PROXY environment variable.

func (*NoProxy) FormatLibcurlCompatible

func (n *NoProxy) FormatLibcurlCompatible(addLoopbackHostnames bool) (string, error)

FormatLibcurlCompatible formats the value of a NO_PROXY environment variable that is compatible with libcurl (see https://curl.haxx.se/libcurl/c/CURLOPT_NOPROXY.html). If the *NoProxy cannot be represented as such then an error is returned. For example, if the *NoProxy contains a CIDR or matches only specific ports of a hostname then an error is returned.

func (*NoProxy) UseProxy

func (n *NoProxy) UseProxy(url1 *url.URL) (bool, error)

Jump to

Keyboard shortcuts

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