net

package
v0.0.0-...-b479636 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendForwardedForHeader

func AppendForwardedForHeader(req *http.Request)

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 ChooseBindAddress

func ChooseBindAddress(bindAddress net.IP) (net.IP, error)

If bind-address is usable, return it directly If bind-address is not usable (unset, 0.0.0.0, or loopback), we will use the host's default interface.

func ChooseHostInterface

func ChooseHostInterface() (net.IP, error)

ChooseHostInterface is a method used fetch an IP for a daemon. It uses data from /proc/net/route file. For a node with no internet connection ,it returns error For a multi n/w interface node it returns the IP of the interface with gateway on it.

func CloneHeader

func CloneHeader(in http.Header) http.Header

CloneHeader creates a deep copy of an http.Header.

func CloneRequest

func CloneRequest(req *http.Request) *http.Request

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) (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.

func FormatURL

func FormatURL(scheme string, host string, port int, path string) *url.URL

func GetClientIP

func GetClientIP(req *http.Request) net.IP

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 GetHTTPClient(req *http.Request) string

func IsProbableEOF

func IsProbableEOF(err error) bool

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 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 SetOldTransportDefaults

func SetOldTransportDefaults(t *http.Transport) *http.Transport

SetOldTransportDefaults applies the defaults from http.DefaultTransport for the Proxy, Dial, and TLSHandshakeTimeout fields if unset

func SetTransportDefaults

func SetTransportDefaults(t *http.Transport) *http.Transport

SetTransportDefaults applies the defaults from http.DefaultTransport for the Proxy, Dial, and TLSHandshakeTimeout fields if unset

func SourceIPs

func SourceIPs(req *http.Request) []net.IP

SourceIPs splits the comma separated X-Forwarded-For header or returns the X-Real-Ip header or req.RemoteAddr, in that order, ignoring invalid IPs. It returns nil if all of these are empty or invalid.

func TLSClientConfig

func TLSClientConfig(transport http.RoundTripper) (*tls.Config, error)

Types

type AddressFamily

type AddressFamily uint

type DialFunc

type DialFunc func(net, addr string) (net.Conn, error)

func DialerFor

func DialerFor(transport http.RoundTripper) (DialFunc, error)

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 RoundTripperWrapper

type RoundTripperWrapper interface {
	http.RoundTripper
	WrappedRoundTripper() http.RoundTripper
}

type Route

type Route struct {
	Interface   string
	Destination net.IP
	Gateway     net.IP
}

type TLSClientConfigHolder

type TLSClientConfigHolder interface {
	TLSClientConfig() *tls.Config
}

Jump to

Keyboard shortcuts

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