Documentation ¶
Index ¶
- Constants
- Variables
- func AddIPOffset(base *big.Int, offset int) net.IP
- func AppendForwardedForHeader(req *http.Request)
- func BigForIP(ip net.IP) *big.Int
- func CanonicalAddr(url *url.URL) string
- func ChooseBindAddressForInterface(intfName string) (net.IP, error)
- func ChooseHostInterface() (net.IP, error)
- func CloneHeader(in http.Header) http.Header
- func CloneRequest(req *http.Request) *http.Request
- func ConnectWithRedirects(originalMethod string, originalLocation *url.URL, header http.Header, ...) (net.Conn, []byte, error)
- func FormatURL(scheme string, host string, port int, path string) *url.URL
- func GetClientIP(req *http.Request) net.IP
- func GetHTTPClient(req *http.Request) string
- func GetIndexedIP(subnet *net.IPNet, index int) (net.IP, error)
- func IPNetEqual(ipnet1, ipnet2 *net.IPNet) bool
- func IsConnectionRefused(err error) bool
- func IsConnectionReset(err error) bool
- func IsDualStackCIDRStrings(cidrs []string) (bool, error)
- func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error)
- func IsDualStackIPStrings(ips []string) (bool, error)
- func IsDualStackIPs(ips []net.IP) (bool, error)
- func IsIPv4(netIP net.IP) bool
- func IsIPv4CIDR(cidr *net.IPNet) bool
- func IsIPv4CIDRString(cidr string) bool
- func IsIPv4String(ip string) bool
- func IsIPv6(netIP net.IP) bool
- func IsIPv6CIDR(cidr *net.IPNet) bool
- func IsIPv6CIDRString(cidr string) bool
- func IsIPv6String(ip string) bool
- func IsNoRoutesError(err error) bool
- func IsProbableEOF(err error) bool
- func IsTimeout(err error) bool
- func JoinPreservingTrailingSlash(elem ...string) string
- func JoinSchemeNamePort(scheme, name, port string) string
- func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error)) func(req *http.Request) (*url.URL, error)
- func NewWarningHeader(code int, agent, text string) (string, error)
- func ParseCIDRs(cidrsString []string) ([]*net.IPNet, error)
- func ParsePort(port string, allowZero bool) (int, error)
- func RangeSize(subnet *net.IPNet) int64
- func ResolveBindAddress(bindAddress net.IP) (net.IP, error)
- func SetOldTransportDefaults(t *http.Transport) *http.Transport
- func SetTransportDefaults(t *http.Transport) *http.Transport
- func SourceIPs(req *http.Request) []net.IP
- func SplitSchemeNamePort(id string) (scheme, name, port string, valid bool)
- func TLSClientConfig(transport http.RoundTripper) (*tls.Config, error)
- type AddressFamily
- type AddressFamilyPreference
- type Closeable
- type DialFunc
- type Dialer
- type DialerFunc
- type IPFamily
- type IPNetSet
- func (s IPNetSet) Delete(items ...*net.IPNet)
- func (s IPNetSet) Difference(s2 IPNetSet) IPNetSet
- func (s IPNetSet) Equal(s2 IPNetSet) bool
- func (s IPNetSet) Has(item *net.IPNet) bool
- func (s IPNetSet) HasAll(items ...*net.IPNet) bool
- func (s IPNetSet) Insert(items ...*net.IPNet)
- func (s IPNetSet) IsSuperset(s2 IPNetSet) bool
- func (s IPNetSet) Len() int
- func (s IPNetSet) StringSlice() []string
- type IPSet
- func (s IPSet) Delete(items ...net.IP)
- func (s IPSet) Difference(s2 IPSet) IPSet
- func (s IPSet) Equal(s2 IPSet) bool
- func (s IPSet) Has(item net.IP) bool
- func (s IPSet) HasAll(items ...net.IP) bool
- func (s IPSet) Insert(items ...net.IP)
- func (s IPSet) IsSuperset(s2 IPSet) bool
- func (s IPSet) Len() int
- func (s IPSet) StringSlice() []string
- type LocalPort
- type PortOpener
- type PortRange
- type Protocol
- type RoundTripperWrapper
- type Route
- type RouteFile
- type TLSClientConfigHolder
- type WarningHeader
Constants ¶
const (
// LoopbackInterfaceName is the default name of the loopback interface
LoopbackInterfaceName = "lo"
)
Variables ¶
var ListenPortOpener listenPortOpener
ListenPortOpener opens ports by calling bind() and listen().
Functions ¶
func AddIPOffset ¶
AddIPOffset adds the provided integer offset to a base big.Int representing a net.IP NOTE: If you started with a v4 address and overflow it, you get a v6 result.
func AppendForwardedForHeader ¶
Prepares the X-Forwarded-For header for another forwarding hop by appending the previous sender's IP address to the X-Forwarded-For chain.
func CanonicalAddr ¶
FROM: http://golang.org/src/net/http/transport.go canonicalAddr returns url.Host but always with a ":port" suffix
func ChooseBindAddressForInterface ¶
ChooseBindAddressForInterface choose a global IP for a specific interface, with priority given to IPv4. This is required in case of network setups where default routes are present, but network interfaces use only link-local addresses (e.g. as described in RFC5549). e.g when using BGP to announce a host IP over link-local ip addresses and this ip address is attached to the lo interface.
func ChooseHostInterface ¶
ChooseHostInterface is a method used fetch an IP for a daemon. If there is no routing info file, it will choose a global IP from the system interfaces. Otherwise, it will use IPv4 and IPv6 route information to return the IP of the interface with a gateway on it (with priority given to IPv4). For a node with no internet connection, it returns error.
func CloneHeader ¶
CloneHeader creates a deep copy of an http.Header.
func CloneRequest ¶
CloneRequest creates a shallow copy of the request along with a deep copy of the Headers.
func ConnectWithRedirects ¶
func ConnectWithRedirects(originalMethod string, originalLocation *url.URL, header http.Header, originalBody io.Reader, dialer Dialer, requireSameHostRedirects bool) (net.Conn, []byte, error)
ConnectWithRedirects uses dialer to send req, following up to 10 redirects (relative to originalLocation). It returns the opened net.Conn and the raw response bytes. If requireSameHostRedirects is true, only redirects to the same host are permitted.
func GetClientIP ¶
Extracts and returns the clients IP from the given request. Looks at X-Forwarded-For header, X-Real-Ip header and request.RemoteAddr in that order. Returns nil if none of them are set or is set to an invalid value.
func GetHTTPClient ¶
func GetIndexedIP ¶
GetIndexedIP returns a net.IP that is subnet.IP + index in the contiguous IP space.
func IPNetEqual ¶
IPNetEqual checks if the two input IPNets are representing the same subnet. For example,
10.0.0.1/24 and 10.0.0.0/24 are the same subnet. 10.0.0.1/24 and 10.0.0.0/25 are not the same subnet.
func IsConnectionRefused ¶
Returns if the given err is "connection refused" error
func IsConnectionReset ¶
Returns if the given err is "connection reset by peer" error.
func IsDualStackCIDRStrings ¶
IsDualStackCIDRStrings returns if - all are valid cidrs - at least one cidr from each family (v4 or v6)
func IsDualStackCIDRs ¶
IsDualStackCIDRs returns if - all are valid cidrs - at least one cidr from each family (v4 or v6)
func IsDualStackIPStrings ¶
IsDualStackIPStrings returns if - all are valid ips - at least one ip from each family (v4 or v6)
func IsDualStackIPs ¶
IsDualStackIPs returns if a slice of ips is: - all are valid ips - at least one ip from each family (v4 or v6)
func IsIPv4CIDRString ¶
IsIPv4CIDRString returns if cidr is IPv4. This assumes cidr is a valid CIDR.
func IsIPv6CIDRString ¶
IsIPv6CIDRString returns if cidr is IPv6. This assumes cidr is a valid CIDR.
func IsNoRoutesError ¶
IsNoRoutesError checks if an error is of type noRoutesError
func IsProbableEOF ¶
IsProbableEOF returns true if the given error resembles a connection termination scenario that would justify assuming that the watch is empty. These errors are what the Go http stack returns back to us which are general connection closure errors (strongly correlated) and callers that need to differentiate probable errors in connection behavior between normal "this is disconnected" should use the method.
func JoinPreservingTrailingSlash ¶
JoinPreservingTrailingSlash does a path.Join of the specified elements, preserving any trailing slash on the last non-empty segment
func JoinSchemeNamePort ¶
JoinSchemeNamePort returns a string that specifies the scheme, name, and port:
- "<name>"
- "<name>:<port>"
- "<scheme>:<name>:<port>"
None of the parameters may contain a ':' character Name is required Scheme must be "", "http", or "https"
func NewProxierWithNoProxyCIDR ¶
func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error)) func(req *http.Request) (*url.URL, error)
NewProxierWithNoProxyCIDR constructs a Proxier function that respects CIDRs in NO_PROXY and delegates if no matching CIDRs are found
func ParseCIDRs ¶
ParseCIDRs parses a list of cidrs and return error if any is invalid. order is maintained
func ParsePort ¶
ParsePort parses a string representing an IP port. If the string is not a valid port number, this returns an error.
func RangeSize ¶
RangeSize returns the size of a range in valid addresses. returns the size of the subnet (or math.MaxInt64 if the range size would overflow int64)
func ResolveBindAddress ¶
ResolveBindAddress returns the IP address of a daemon, based on the given bindAddress: If bindAddress is unset, it returns the host's default IP, as with ChooseHostInterface(). If bindAddress is unspecified or loopback, it returns the default IP of the same address family as bindAddress. Otherwise, it just returns bindAddress.
func SetOldTransportDefaults ¶
SetOldTransportDefaults applies the defaults from http.DefaultTransport for the Proxy, Dial, and TLSHandshakeTimeout fields if unset
func SetTransportDefaults ¶
SetTransportDefaults applies the defaults from http.DefaultTransport for the Proxy, Dial, and TLSHandshakeTimeout fields if unset
func SourceIPs ¶
SourceIPs splits the comma separated X-Forwarded-For header and joins it with the X-Real-Ip header and/or req.RemoteAddr, ignoring invalid IPs. The X-Real-Ip is omitted if it's already present in the X-Forwarded-For chain. The req.RemoteAddr is always the last IP in the returned list. It returns nil if all of these are empty or invalid.
func SplitSchemeNamePort ¶
SplitSchemeNamePort takes a string of the following forms:
- "<name>", returns "", "<name>","", true
- "<name>:<port>", returns "", "<name>","<port>",true
- "<scheme>:<name>:<port>", returns "<scheme>","<name>","<port>",true
Name must be non-empty or valid will be returned false. Scheme must be "http" or "https" if specified Port is returned as a string, and it is not required to be numeric (could be used for a named port, for example).
func TLSClientConfig ¶
func TLSClientConfig(transport http.RoundTripper) (*tls.Config, error)
Types ¶
type AddressFamily ¶
type AddressFamily uint
type AddressFamilyPreference ¶
type AddressFamilyPreference []AddressFamily
type Dialer ¶
type Dialer interface { // Dial connects to the host specified by req's URL, writes the request to the connection, and // returns the opened net.Conn. Dial(req *http.Request) (net.Conn, error) }
Dialer dials a host and writes a request to it.
type DialerFunc ¶
DialerFunc implements Dialer for the provided function.
type IPFamily ¶
type IPFamily string
IPFamily refers to a specific family if not empty, i.e. "4" or "6".
const ( IPv4 IPFamily = "4" IPv6 = "6" )
Constants for valid IPFamilys:
type IPNetSet ¶
IPNetSet maps string to net.IPNet.
func ParseIPNets ¶
ParseIPNets parses string slice to IPNetSet.
func (IPNetSet) Difference ¶
Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}
func (IPNetSet) Equal ¶
Equal returns true if and only if s1 is equal (as a set) to s2. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)
func (IPNetSet) IsSuperset ¶
IsSuperset returns true if and only if s1 is a superset of s2.
func (IPNetSet) StringSlice ¶
StringSlice returns a []string with the String representation of each element in the set. Order is undefined.
type IPSet ¶
IPSet maps string to net.IP
func ParseIPSet ¶
ParseIPSet parses string slice to IPSet
func (IPSet) Difference ¶
Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}
func (IPSet) Equal ¶
Equal returns true if and only if s1 is equal (as a set) to s2. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)
func (IPSet) IsSuperset ¶
IsSuperset returns true if and only if s1 is a superset of s2.
func (IPSet) StringSlice ¶
StringSlice returns a []string with the String representation of each element in the set. Order is undefined.
type LocalPort ¶
type LocalPort struct { // Description is an arbitrary string. Description string // IP is the IP address part of a given local port. // If this string is empty, the port binds to all local IP addresses. IP string // If IPFamily is not empty, the port binds only to addresses of this // family. // IF empty along with IP, bind to local addresses of any family. IPFamily IPFamily // Port is the port number. // A value of 0 causes a port to be automatically chosen. Port int // Protocol is the protocol, e.g. TCP Protocol Protocol }
LocalPort represents an IP address and port pair along with a protocol and potentially a specific IP family. A LocalPort can be opened and subsequently closed.
type PortOpener ¶
PortOpener can open a LocalPort and allows later closing it.
type PortRange ¶
PortRange represents a range of TCP/UDP ports. To represent a single port, set Size to 1.
func ParsePortRange ¶
ParsePortRange parses a string of the form "min-max", inclusive at both ends, and initializes a new PortRange from it.
func ParsePortRangeOrDie ¶
func (*PortRange) Set ¶
Set parses a string of the form "value", "min-max", or "min+offset", inclusive at both ends, and sets the PortRange from it. This is part of the flag.Value and pflag.Value interfaces.
type RoundTripperWrapper ¶
type RoundTripperWrapper interface { http.RoundTripper WrappedRoundTripper() http.RoundTripper }
type TLSClientConfigHolder ¶
type WarningHeader ¶
type WarningHeader struct { // Codeindicates the type of warning. 299 is a miscellaneous persistent warning Code int // Agent contains the name or pseudonym of the server adding the Warning header. // A single "-" is recommended when agent is unknown. Agent string // Warning text Text string }
WarningHeader contains a single RFC2616 14.46 warnings header
func ParseWarningHeader ¶
func ParseWarningHeader(header string) (result WarningHeader, remainder string, err error)
ParseWarningHeader extracts one RFC2616 14.46 warning from the specified header, returning an error if the header does not contain a correctly formatted warning. Any remaining content in the header is returned.
func ParseWarningHeaders ¶
func ParseWarningHeaders(headers []string) ([]WarningHeader, []error)
ParseWarningHeaders extract RFC2616 14.46 warnings headers from the specified set of header values. Multiple comma-separated warnings per header are supported. If errors are encountered on a header, the remainder of that header are skipped and subsequent headers are parsed. Returns successfully parsed warnings and any errors encountered.