httputil

package
v0.0.0-...-c7fba9c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugRequest = debugflag(1 << iota)
	DebugResponse
	DebugBody
)

set these via the Key environ

Variables

This section is empty.

Functions

func BaseTransport

func BaseTransport(cli *http.Client) *http.Transport

BaseTransport returns the underlying http.Transport of a client created with NewHTTPClient. It panics if that's not the case. For tests.

func MaybeLogRetryAttempt

func MaybeLogRetryAttempt(url string, attempt *retry.Attempt, startTime time.Time)

func MockResponseHeaderTimeout

func MockResponseHeaderTimeout(d time.Duration) (restore func())

func NewHTTPClient

func NewHTTPClient(opts *ClientOptions) *http.Client

NewHTTPCLient returns a new http.Client with a LoggedTransport, a Timeout and preservation of range requests across redirects

func NoNetwork

func NoNetwork(err error) (b bool)

NoNetwork returns true if the error indicates that there is no network connection available, i.e. network unreachable or down or DNS unavailable.

func RetryRequest

func RetryRequest(endpoint string, doRequest func() (*http.Response, error), readResponseBody func(resp *http.Response) error, retryStrategy retry.Strategy) (resp *http.Response, err error)

RetryRequest calls doRequest and read the response body in a retry loop using the given retryStrategy.

func ShouldRetryAttempt

func ShouldRetryAttempt(attempt *retry.Attempt, err error) bool

func ShouldRetryError

func ShouldRetryError(err error) (b bool)

ShouldRetryError returns true for transient network errors like when the remote side returns a connection reset and it's sensible to retry after a short time.

XXX: Note that currently also NoNetwork(err) errors are reported with true here.

func ShouldRetryHttpResponse

func ShouldRetryHttpResponse(attempt *retry.Attempt, resp *http.Response) bool

Types

type CertData

type CertData struct {
	Raw    []byte
	Origin string
}

CertData contains the raw data of a certificate and the origin of the cert, this is usually a file path on disk and is just used for error reporting.

type ClientOptions

type ClientOptions struct {
	Timeout    time.Duration
	TLSConfig  *tls.Config
	MayLogBody bool

	Proxy              func(*http.Request) (*url.URL, error)
	ProxyConnectHeader http.Header

	ExtraSSLCerts ExtraSSLCerts
}

type ExtraSSLCerts

type ExtraSSLCerts interface {
	Certs() ([]*CertData, error)
}

ExtraSSLCerts is an interface that provides a way to add extra SSL certificates to the httputil.Client

type ExtraSSLCertsFromDir

type ExtraSSLCertsFromDir struct {
	Dir string
}

ExtraSSLCertsFromDir implements ExtraSSLCerts and provides all the pem encoded certs from the given directory.

func (*ExtraSSLCertsFromDir) Certs

func (e *ExtraSSLCertsFromDir) Certs() ([]*CertData, error)

Certs returns a slice CertData or an error.

type LoggedTransport

type LoggedTransport struct {
	Transport http.RoundTripper
	Key       string
	// contains filtered or unexported fields
}

LoggedTransport is an http.RoundTripper that can be used by http.Client to log request/response roundtrips.

func (*LoggedTransport) RoundTrip

func (tr *LoggedTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is from the http.RoundTripper interface.

type PersistentNetworkError

type PersistentNetworkError struct {
	Err error
}

func (*PersistentNetworkError) Error

func (e *PersistentNetworkError) Error() string

Jump to

Keyboard shortcuts

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