httputil

package
v0.0.0-...-5fe3b72 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRoundRobinTransport

func NewRoundRobinTransport(cfg RoundRobinTransportConfig) http.RoundTripper

func WithAuthz

func WithAuthz(transport http.RoundTripper, value string) http.RoundTripper

Wraps a RoundTripper with one that injects an HTTP Authorization header

func WithMetrics

func WithMetrics(trans http.RoundTripper, prefix string) http.RoundTripper

func WithRetries

func WithRetries(base http.RoundTripper, options ...RetryOptions) http.RoundTripper

Types

type ContentRange

type ContentRange struct {
	First uint64
	Last  uint64
	Total uint64
}

func GetContentRange

func GetContentRange(resp *http.Response) (*ContentRange, error)

func (ContentRange) Len

func (cr ContentRange) Len() uint64

func (ContentRange) Terminal

func (cr ContentRange) Terminal() bool

type DialFunc

type DialFunc func(ctx context.Context, network string, addr string) (conn net.Conn, err error)

type LookupHostFunc

type LookupHostFunc func(host string) (addrs []string, err error)

type RetryOptions

type RetryOptions struct {
	InitialInterval time.Duration
	MaxInterval     time.Duration
	MaxElapsedTime  time.Duration
}

type RoundRobinTransportConfig

type RoundRobinTransportConfig struct {
	// TLSClientConfig specifies the TLS configuration to use with
	// tls.Client.
	// If nil, the default configuration is used.
	// If non-nil, HTTP/2 support may not be enabled by default.
	TLSClientConfig *tls.Config

	// TLSHandshakeTimeout specifies the maximum amount of time waiting to
	// wait for a TLS handshake. Zero means no timeout.
	TLSHandshakeTimeout time.Duration // Go 1.3

	// MaxHosts controls the number of hosts for which we maintain
	// RoundTrippers. Zero means no limit.
	MaxHosts int

	// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
	// (keep-alive) connections to keep per-host. If zero,
	// DefaultMaxIdleConnsPerHost is used.
	MaxIdleConnsPerHost int

	// MaxConnsPerHost optionally limits the total number of
	// connections per host, including connections in the dialing,
	// active, and idle states. On limit violation, dials will block.
	//
	// Zero means no limit.
	MaxConnsPerHost int // Go 1.11

	// IdleConnTimeout is the maximum amount of time an idle
	// (keep-alive) connection will remain idle before closing
	// itself.
	// Zero means no limit.
	IdleConnTimeout time.Duration // Go 1.7

	// ResponseHeaderTimeout, if non-zero, specifies the amount of
	// time to wait for a server's response headers after fully
	// writing the request (including its body, if any). This
	// time does not include the time to read the response body.
	ResponseHeaderTimeout time.Duration // Go 1.1

	// ExpectContinueTimeout, if non-zero, specifies the amount of
	// time to wait for a server's first response headers after fully
	// writing the request headers if the request has an
	// "Expect: 100-continue" header. Zero means no timeout and
	// causes the body to be sent immediately, without
	// waiting for the server to approve.
	// This time does not include the time to send the request header.
	ExpectContinueTimeout time.Duration // Go 1.6

	// ProxyConnectHeader optionally specifies headers to send to
	// proxies during CONNECT requests.
	ProxyConnectHeader http.Header // Go 1.8

	// MaxResponseHeaderBytes specifies a limit on how many
	// response bytes are allowed in the server's response
	// header.
	//
	// Zero means to use a default limit.
	MaxResponseHeaderBytes int64 // Go 1.7

	// WriteBufferSize specifies the size of the write buffer used
	// when writing to the transport.
	// If zero, a default (currently 4KB) is used.
	WriteBufferSize int // Go 1.13

	// ReadBufferSize specifies the size of the read buffer used
	// when reading from the transport.
	// If zero, a default (currently 4KB) is used.
	ReadBufferSize int // Go 1.13

	// ForceAttemptHTTP2 controls whether HTTP/2 is enabled when a non-zero
	// Dial, DialTLS, or DialContext func or TLSClientConfig is provided.
	// By default, use of any those fields conservatively disables HTTP/2.
	// To use a custom dialer or TLS config and still attempt HTTP/2
	// upgrades, set this to true.
	ForceAttemptHTTP2 bool // Go 1.13

	// DialerTimeout is the maximum amount of time a dial will wait
	// for a connect to complete.
	DialerTimeout time.Duration

	// LookupHost looks up the given host using the local resolver. It
	// returns a slice of that host's addresses. Used for testing.
	LookupHost LookupHostFunc

	// Dial allows injection of a DialFunc for testing.
	Dial DialFunc
}

Jump to

Keyboard shortcuts

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