httputil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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 GetQueryArg

func GetQueryArg(r *http.Request, name string, defaultVal string) string

GetQueryArg gets an argument from http.Request by name. When the argument is not specified, it returns a default value.

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 IsStatus

func IsStatus(err error, status int) bool

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

func ParseDigest

func ParseDigest(r *http.Request, name string) (core.Digest, error)

ParseDigest parses a digest from url.

func ParseParam

func ParseParam(r *http.Request, name string) (string, error)

ParseParam parses a parameter from url.

func Patch

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

Patch sends a PATCH http request.

func PollAccepted

func PollAccepted(
	url string, b backoff.BackOff, options ...SendOption) (*http.Response, error)

PollAccepted wraps GET requests for endpoints which require 202-polling.

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 ExponentialBackOffConfig added in v0.1.2

type ExponentialBackOffConfig struct {
	Enabled             bool          `yaml:"enabled"`
	InitialInterval     time.Duration `yaml:"initial_interval"`
	RandomizationFactor float64       `yaml:"randomization_factor"`
	Multiplier          float64       `yaml:"multiplier"`
	MaxInterval         time.Duration `yaml:"max_interval"`
	MaxRetries          uint64        `yaml:"max_retries"`
}

ExponentialBackOffConfig maps backoff settings into YAML config format.

func (ExponentialBackOffConfig) Build added in v0.1.2

Build creates a new ExponentialBackOff using c's settings (if enabled).

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

func RetryBackoff(b backoff.BackOff) RetryOption

RetryBackoff adds exponential backoff between retries.

func RetryCodes

func RetryCodes(codes ...int) RetryOption

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

WARNING: You better know what you're doing to retry anything non-5XX.

type RoundTripper added in v0.1.2

type RoundTripper = http.RoundTripper

RoundTripper is an alias of the http.RoundTripper for mocking purposes.

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.2

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 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"`
	Server X509Pair `yaml:"server"`
	Client X509Pair `yaml:"client"`
	CAs    []Secret `yaml:"cas"`
	// 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.

func (*TLSConfig) WriteCABundle

func (c *TLSConfig) WriteCABundle(w io.Writer) error

WriteCABundle writes a list of CA to a writer.

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