httputil

package
v2.42.5-go-mod+incompa... Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: GPL-3.0 Imports: 18 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 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 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 SetUserAgentFromVersion

func SetUserAgentFromVersion(version string, extraProds ...string) (restore func())

SetUserAgentFromVersion sets up a user-agent string.

func ShouldRetryError

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

func ShouldRetryHttpResponse

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

func UserAgent

func UserAgent() string

UserAgent returns the user-agent string setup through SetUserAgentFromVersion.

Types

type ClientOptions

type ClientOptions struct {
	Timeout    time.Duration
	TLSConfig  *tls.Config
	MayLogBody bool
	Proxy      func(*http.Request) (*url.URL, 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 PerstistentNetworkError

type PerstistentNetworkError struct {
	Err error
}

func (*PerstistentNetworkError) Error

func (e *PerstistentNetworkError) Error() string

Jump to

Keyboard shortcuts

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