httpkit

package
v0.165.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

httputil

This package provides a set of utilities for working with HTTP requests and responses.

RoundTripperFunc

RoundTripperFunc is a type that allows you to create an HTTP RoundTripper from a function that takes an HTTP request and returns an HTTP response and an error. This is useful for creating custom middleware to be used with the http.Client or the http.Transport.

RetryRoundTripper

RetryRoundTripper is a type that wraps an existing http.RoundTripper and provides a mechanism for retrying failed requests. This is useful for dealing with transient errors that can occur when making HTTP requests.

The RetryRoundTripper retries requests in case of a recoverable error (such as network timeouts or temporary server errors) up to a certain number of times. If the retries exceed the maximum number of retries, the last response and error are returned.

The RetryRoundTripper considers the following errors as retriable:

  • http.ErrHandlerTimeout
  • net.ErrClosed,
  • and timeout errors

The RetryRoundTripper considers HTTP responses with the following status codes as temporary errors:

  • Internal server error
  • Bad gateway
  • Gateway timeout
  • Service unavailable
  • Insufficient storage
  • Too many requests
  • Request timeout

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessLog

type AccessLog struct {
	Next http.Handler

	AdditionalLoggingDetail func(w http.ResponseWriter, r *http.Request) logger.LoggingDetail
}

func (AccessLog) ServeHTTP

func (mw AccessLog) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RetryRoundTripper

type RetryRoundTripper struct {
	// Transport specifies the mechanism by which individual
	// HTTP requests are made.
	//
	// Default: http.DefaultTransport
	Transport http.RoundTripper
	// RetryStrategy will be used to evaluate if a new retry attempt should be done.
	//
	// Default: retry.ExponentialBackoff
	RetryStrategy retry.Strategy
}

func (RetryRoundTripper) RoundTrip

func (rt RetryRoundTripper) RoundTrip(request *http.Request) (resp *http.Response, err error)

RoundTrip

TODO: optional waiting based on the Retry-After header

type RoundTripperFunc

type RoundTripperFunc func(request *http.Request) (*http.Response, error)

func (RoundTripperFunc) RoundTrip

func (fn RoundTripperFunc) RoundTrip(request *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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