httputil

package
v0.0.0-...-8b28c38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextWarning string = "Warning"
	ContextName    string = "Name"
	ContextQuery   string = "Query"
)

Variables

This section is empty.

Functions

func ExponentialBackoffWaitFor

func ExponentialBackoffWaitFor(defaultWait time.Duration, retry int) time.Duration

ExpontentialBackoffWatiFor accepts a default wait duration and the current retry count and returns a new duration

func GetName

func GetName(r *http.Request) (name string, ok bool)

GetName Extracts a name value from the request context if it exists

func GetQuery

func GetQuery(r *http.Request) (name string, ok bool)

GetQuery Extracts a query value from the request context if it exists

func GetWarning

func GetWarning(r *http.Request) (warning string, ok bool)

GetWarning Extracts a warning message from the request context if it exists

func HeaderString

func HeaderString(h http.Header) string

HeaderString writes the request/response http.Header to a string.

func IsRateLimited

func IsRateLimited(resp *http.Response, body []byte) bool

IsRateLimited accepts a response and body to determine if either indicate a rate limited return

func IsRateLimitedBody

func IsRateLimitedBody(resp *http.Response, body []byte) bool

IsRateLimitedBody attempts to determine if a response body indicates throttling has occurred. This function is a result of some API providers (AWS) returning a 400 status code instead of 429 for rate limit exceptions.

func IsRateLimitedResponse

func IsRateLimitedResponse(resp *http.Response) bool

IsRateLimitedResponse returns true if the status code is a 429 (TooManyRequests)

func NewUserAgentTransport

func NewUserAgentTransport(userAgent string, base http.RoundTripper) http.RoundTripper

NewUserAgentTransport creates a RoundTripper that attaches the configured user agent.

func RateLimitedRetryFor

func RateLimitedRetryFor(resp *http.Response, defaultWait time.Duration, retry int) time.Duration

RateLimitedRetryFor returns the parsed Retry-After header relative to the current time. If the Retry-After header does not exist, the defaultWait parameter is returned.

func SetName

func SetName(r *http.Request, name string) *http.Request

SetName Sets the name value on the provided request and returns a new instance of the request with the new context.

func SetQuery

func SetQuery(r *http.Request, query string) *http.Request

SetQuery Sets the query value on the provided request and returns a new instance of the request with the new context.

func SetWarning

func SetWarning(r *http.Request, warning string) *http.Request

SetWarning Sets the warning context on the provided request and returns a new instance of the request with the new context.

Types

type QueryParams

type QueryParams interface {
	mapper.PrimitiveMap

	// InvalidKeys returns the set of param keys which are not present in the
	// possible valid set. It is a set subtraction: present - valid = invalid
	//
	// Example usage to catch a typo:
	// qp.InvalidKeys([]string{"window", "aggregate", "filterClusters"}) ->
	//   "filterClsuters"
	//
	// If qp contains no keys, then this should always return an empty slice/nil
	InvalidKeys(possibleValidKeys []string) (invalidKeys []string)
}

QueryParams provides basic map access to URL values as well as providing helpful additional functionality for validation.

func NewQueryParams

func NewQueryParams(values url.Values) QueryParams

NewQueryParams creates a primitive map using the request query parameters

Jump to

Keyboard shortcuts

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