net

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MinTotalBackoffDuration

func MinTotalBackoffDuration(backoff wait.Backoff) time.Duration

MinTotalBackoffDuration returns the minimum duration that backoff would wait, including all steps, not including any jitter

func NewNetDialer

func NewNetDialer(connectTimeout, keepAlive time.Duration) *net.Dialer

NewNetDialer creates a new (net).Dialer with the given connection timeout and keep alive duration.

func StartTestServer

func StartTestServer(hdl http.Handler) (*httptest.Server, *url.URL, error)

StartTestServer creates and starts an *httptest.Server in the background, then parses its URL and returns both values.

If this function returns a nil error, the caller is responsible for closing the returned server. If it returns a non-nil error, the server and URL will be nil.

Types

type DialContextFunc

type DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialContextFunc is a function that matches the (net).Dialer.DialContext functions's signature

func DialContextWithRetry

func DialContextWithRetry(coreDialer *net.Dialer, backoff wait.Backoff) DialContextFunc

DialContextWithRetry creates a new DialContextFunc -- which has the same signature as the net.Conn.DialContext function -- that calls coreDialer.DialContext multiple times with an exponential backoff. The timeout of the first dial will be coreDialer.Timeout, and it will multiply by a factor of two from there.

This function is mainly used in the interceptor so that, once it sees that the target deployment has 1 or more replicas, it can forward the request. If the deployment's state changed in the time slice between detecting >=1 replicas and the network send, the connection will be retried a few times.

Thanks to Knative for inspiring this code. See GitHub link below https://github.com/knative/serving/blob/20815258c92d0f26100031c71a91d0bef930a475/vendor/knative.dev/pkg/network/transports.go#L70

type TestHTTPHandlerWrapper

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

func NewTestHTTPHandlerWrapper

func NewTestHTTPHandlerWrapper(hdl http.Handler) *TestHTTPHandlerWrapper

func (*TestHTTPHandlerWrapper) IncomingRequests

func (t *TestHTTPHandlerWrapper) IncomingRequests() []http.Request

IncomingRequests returns a copy slice of all the requests that have been received before this function was called.

func (*TestHTTPHandlerWrapper) ServeHTTP

Jump to

Keyboard shortcuts

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