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 ¶
- Variables
- func Delete(url string, options ...SendOption) (*http.Response, error)
- func Get(url string, options ...SendOption) (*http.Response, error)
- func GetQueryArg(r *http.Request, name string, defaultVal string) string
- func Head(url string, options ...SendOption) (*http.Response, error)
- func IsAccepted(err error) bool
- func IsConflict(err error) bool
- func IsCreated(err error) bool
- func IsForbidden(err error) bool
- func IsNetworkError(err error) bool
- func IsNotFound(err error) bool
- func IsStatus(err error, status int) bool
- func ParseDigest(r *http.Request, name string) (core.Digest, error)
- func ParseParam(r *http.Request, name string) (string, error)
- func Patch(url string, options ...SendOption) (*http.Response, error)
- func PollAccepted(url string, b backoff.BackOff, options ...SendOption) (*http.Response, error)
- func Post(url string, options ...SendOption) (*http.Response, error)
- func Put(url string, options ...SendOption) (*http.Response, error)
- func Send(method, rawurl string, options ...SendOption) (*http.Response, error)
- type ExponentialBackOffConfig
- type NetworkError
- type RetryOption
- type RoundTripper
- type Secret
- type SendOption
- func DisableHTTPFallback() SendOption
- func SendAcceptedCodes(codes ...int) SendOption
- func SendBody(body io.Reader) SendOption
- func SendContext(ctx context.Context) SendOption
- func SendHeaders(headers map[string]string) SendOption
- func SendNoop() SendOption
- func SendRedirect(redirect func(req *http.Request, via []*http.Request) error) SendOption
- func SendRetry(options ...RetryOption) SendOption
- func SendTLS(config *tls.Config) SendOption
- func SendTLSTransport(transport http.RoundTripper) SendOption
- func SendTimeout(timeout time.Duration) SendOption
- func SendTransport(transport http.RoundTripper) SendOption
- type StatusError
- type TLSConfig
- type X509Pair
Constants ¶
This section is empty.
Variables ¶
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 ¶
GetQueryArg gets an argument from http.Request by name. When the argument is not specified, it returns a default value.
func Head ¶
func Head(url string, options ...SendOption) (*http.Response, error)
Head sends a HEAD http request.
func IsAccepted ¶
IsAccepted returns true if err is a "status accepted" StatusError.
func IsConflict ¶
IsConflict returns true if err is a "status conflict" StatusError.
func IsForbidden ¶
IsForbidden returns true if statis code is 403 "forbidden"
func IsNetworkError ¶
IsNetworkError returns true if err is a NetworkError.
func IsNotFound ¶
IsNotFound returns true if err is a "not found" StatusError.
func ParseDigest ¶
ParseDigest parses a digest from url.
func ParseParam ¶
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 ¶
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.
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
func (c ExponentialBackOffConfig) Build() backoff.BackOff
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.1
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.1
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 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 SendRedirect ¶
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 ¶
BuildClient builts tls.Config for http client.