httputil

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyCommonName = errors.New("empty common name")

ErrEmptyCommonName is returned when common name is not provided for key generation.

Functions

func Delete

func Delete(url string, options ...SendOption) (*http.Response, error)

Delete sends a DELETE http request.

func Get

func Get(url string, options ...SendOption) (*http.Response, error)

Get sends a GET http request.

func Head(url string, options ...SendOption) (*http.Response, error)

Head sends a HEAD http request.

func IsAccepted

func IsAccepted(err error) bool

IsAccepted returns true if err is a "status accepted" StatusError.

func IsConflict

func IsConflict(err error) bool

IsConflict returns true if err is a "status conflict" StatusError.

func IsCreated

func IsCreated(err error) bool

IsCreated returns true if err is a "created", 201

func IsForbidden

func IsForbidden(err error) bool

IsForbidden returns true if statis code is 403 "forbidden"

func IsNetworkError

func IsNetworkError(err error) bool

IsNetworkError returns true if err is a NetworkError.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is a "not found" StatusError.

func IsRetryable added in v0.4.0

func IsRetryable(err error) bool

IsRetryable returns true if the statis code indicates that the request is retryable.

func IsStatus

func IsStatus(err error, status int) bool

IsStatus returns true if err is a StatusError of the given status.

func Patch

func Patch(url string, options ...SendOption) (*http.Response, error)

Patch sends a PATCH http request.

func Post

func Post(url string, options ...SendOption) (*http.Response, error)

Post sends a POST http request.

func Put

func Put(url string, options ...SendOption) (*http.Response, error)

Put sends a PUT http request.

func Send

func Send(method, rawurl string, options ...SendOption) (*http.Response, error)

Send sends an HTTP request. May return NetworkError or StatusError (see above).

Types

type NetworkError

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

NetworkError occurs on any Send error which occurred while trying to send the HTTP request, e.g. the given host is unresponsive.

func (NetworkError) Error

func (e NetworkError) Error() string

type RetryOption

type RetryOption func(*retryOptions)

RetryOption allows overriding defaults for the SendRetry option.

func RetryBackoff added in v0.1.1

func RetryBackoff(b backoff.BackOff) RetryOption

RetryBackoff adds exponential backoff between retries.

func RetryCodes added in v0.4.0

func RetryCodes(codes ...int) RetryOption

RetryCodes adds more status codes to be retried (in addition to the default retryableCodes).

type Secret

type Secret struct {
	Path string `yaml:"path"`
}

Secret contains secret path configuration.

type SendOption

type SendOption func(*sendOptions)

SendOption allows overriding defaults for the Send function.

func DisableHTTPFallback added in v0.1.10

func DisableHTTPFallback() SendOption

DisableHTTPFallback disables http fallback when https request fails.

func SendAcceptedCodes

func SendAcceptedCodes(codes ...int) SendOption

SendAcceptedCodes specifies accepted codes for http request

func SendBody

func SendBody(body io.Reader) SendOption

SendBody specifies a body for http request

func SendClient

func SendClient(client *http.Client) SendOption

SendClient specifies a http client.

func SendContext

func SendContext(ctx context.Context) SendOption

SendContext sets the context for the HTTP client.

func SendHeaders

func SendHeaders(headers map[string]string) SendOption

SendHeaders specifies headers for http request

func SendNoop

func SendNoop() SendOption

SendNoop returns a no-op option.

func SendRedirect

func SendRedirect(redirect func(req *http.Request, via []*http.Request) error) SendOption

SendRedirect specifies a redirect policy for http request

func SendRetry

func SendRetry(options ...RetryOption) SendOption

SendRetry will we retry the request on network / 5XX errors.

func SendTLS

func SendTLS(config *tls.Config) SendOption

SendTLS sets the transport with TLS config for the HTTP client.

func SendTLSTransport

func SendTLSTransport(transport http.RoundTripper) SendOption

SendTLSTransport sets the transport with TLS config for the HTTP client.

func SendTimeout

func SendTimeout(timeout time.Duration) SendOption

SendTimeout specifies timeout for http request

func SendTransport

func SendTransport(transport http.RoundTripper) SendOption

SendTransport sets the transport for the HTTP client.

type StatusError

type StatusError struct {
	Method       string
	URL          string
	Status       int
	Header       http.Header
	ResponseDump string
}

StatusError occurs if an HTTP response has an unexpected status code.

func NewStatusError

func NewStatusError(resp *http.Response) StatusError

NewStatusError returns a new StatusError.

func (StatusError) Error

func (e StatusError) Error() string

type TLSConfig

type TLSConfig struct {
	Name   string   `yaml:"name"`
	CA     X509Pair `yaml:"ca"`
	Client X509Pair `yaml:"client"`
	// contains filtered or unexported fields
}

TLSConfig defines TLS configuration.

func (*TLSConfig) BuildClient

func (c *TLSConfig) BuildClient() (*tls.Config, error)

BuildClient builts tls.Config for http client.

type X509Pair

type X509Pair struct {
	Disabled   bool   `yaml:"disabled"`
	Cert       Secret `yaml:"cert"`
	Key        Secret `yaml:"key"`
	Passphrase Secret `yaml:"passphrase"`
}

X509Pair contains x509 cert configuration. Both Cert and Key should be already in pem format.

Jump to

Keyboard shortcuts

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