http
v0.0.0-20201211155254-580bfa936f22
Documentation
pkg.go.dev ↗Functions
HasContentType
func HasContentType(r *http.Request, mimetypes ...string) bool
HasContentType determines whether the request `content-type` includes a server-acceptable mime-type
Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`)
MustNewRequest
func MustNewRequest(method, url string, body io.Reader, contentType string) *http.Request
MustNewRequest returns a new *http.Request or fatals.
NewRequestForm
func NewRequestForm(method, url string, data url.Values) (*http.Request, error)
NewRequestForm returns a new POST Form *http.Request.
NewRequestJSON
func NewRequestJSON(method, url string, data interface{}) (*http.Request, error)
NewRequestJSON returns a new JSON *http.Request.
NewResilientClientLatencyToleranceConfigurable
func NewResilientClientLatencyToleranceConfigurable(rt http.RoundTripper, timeout time.Duration, backOffDieAfter time.Duration) *http.Client
NewResilientClientLatencyToleranceConfigurable creates a new http.Client for environments with configurable latency tolerance. If transport is set (not nil) it will be wrapped by NewDefaultResilientRoundTripper.
NewResilientClientLatencyToleranceExtreme
func NewResilientClientLatencyToleranceExtreme(rt http.RoundTripper) *http.Client
NewResilientClientLatencyToleranceExtreme creates a new http.Client for environments with extreme latency tolerance. If transport is set (not nil) it will be wrapped by NewDefaultResilientRoundTripper. The client will stop requests after 30 minutes.
NewResilientClientLatencyToleranceHigh
func NewResilientClientLatencyToleranceHigh(rt http.RoundTripper) *http.Client
NewResilientClientLatencyToleranceHigh creates a new http.Client for environments with high latency tolerance. If transport is set (not nil) it will be wrapped by NewDefaultResilientRoundTripper. The client will stop requests after 15 seconds.
NewResilientClientLatencyToleranceMedium
func NewResilientClientLatencyToleranceMedium(rt http.RoundTripper) *http.Client
NewResilientClientLatencyToleranceMedium creates a new http.Client for environments with medium latency tolerance. If transport is set (not nil) it will be wrapped by NewDefaultResilientRoundTripper. The client will stop requests after 5 seconds.
NewResilientClientLatencyToleranceSmall
func NewResilientClientLatencyToleranceSmall(rt http.RoundTripper) *http.Client
NewResilientClientLatencyToleranceSmall creates a new http.Client for environments with small latency tolerance. If transport is set (not nil) it will be wrapped by NewDefaultResilientRoundTripper.
Types
CompressionRequestReader
type CompressionRequestReader struct {
ErrHandler func(w http.ResponseWriter, r *http.Request, err error)
}
NewCompressionRequestReader
func NewCompressionRequestReader(eh func(w http.ResponseWriter, r *http.Request, err error)) *CompressionRequestReader
CompressionRequestReader.ServeHTTP
func (c *CompressionRequestReader) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
ResilientRoundTripper
type ResilientRoundTripper struct {
// RoundTripper the wrapped RoundTripper.
http.RoundTripper
// ShouldRetry defines a strategy for retries.
ShouldRetry RetryPolicy
MaxInterval time.Duration
MaxElapsedTime time.Duration
}
ResilientRoundTripper wraps a RoundTripper and retries requests on failure.
NewDefaultResilientRoundTripper
func NewDefaultResilientRoundTripper( backOffMaxInterval time.Duration, backOffDieAfter time.Duration, ) *ResilientRoundTripper
NewDefaultResilientRoundTripper returns a new ResilientRoundTripper with defaults.
NewResilientRoundTripper
func NewResilientRoundTripper( roundTripper http.RoundTripper, backOffMaxInterval time.Duration, backOffDieAfter time.Duration, ) *ResilientRoundTripper
NewResilientRoundTripper returns a new ResilientRoundTripper.
ResilientRoundTripper.RoundTrip
func (rt *ResilientRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)
RoundTrip executes a single HTTP transaction, returning a Response for the provided Request.
ResilientRoundTripper.WithShouldRetry
func (rt *ResilientRoundTripper) WithShouldRetry(policy RetryPolicy) *ResilientRoundTripper
WithShouldRetry sets a RetryPolicy.
RetryPolicy
type RetryPolicy func(*http.Response, error) (retry bool)
RetryPolicy returns true if the request should be retried.
LoggedShouldRetry
func LoggedShouldRetry(l *logrusx.Logger) RetryPolicy
LoggedShouldRetry returns a RetryPolicy that logs erros.