httputils

package
v0.0.0-...-00ec399 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentHandler

func InstrumentHandler(reg prometheus.Registerer, metricsOpts prometheus.Opts, labeller func(req *http.Request, resp *http.Response) prometheus.Labels, h http.Handler) http.Handler

func StandardHandlerLabeller

func StandardHandlerLabeller(req *http.Request, resp *http.Response) prometheus.Labels

func StandardRoundTripLabeller

func StandardRoundTripLabeller(req *http.Request, resp *http.Response) prometheus.Labels

Types

type ForcedCacheTransport

type ForcedCacheTransport struct {
	Transport     http.RoundTripper
	CacheDuration time.Duration
}

ForcedCacheTransport forces the cache headers of http responses so subsequent caching libraries can cache the responses regardless of their original contents

func (*ForcedCacheTransport) RoundTrip

func (t *ForcedCacheTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)

type MonitoredRoundTripper

type MonitoredRoundTripper struct {
	// Transport allows to customize the underneath RoundTripper
	// If not provided, http.DefaultTransport will be used
	Transport    http.RoundTripper
	CallsCounter *prometheus.CounterVec
	Timings      prometheus.HistogramVec
	Labeller     func(req *http.Request, resp *http.Response) prometheus.Labels
}

func NewMonitoredRoundTripper

func NewMonitoredRoundTripper(reg prometheus.Registerer, metricsOpts prometheus.Opts, labeller func(req *http.Request, resp *http.Response) prometheus.Labels) *MonitoredRoundTripper

func (*MonitoredRoundTripper) RoundTrip

func (t *MonitoredRoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error)

type RateLimitedRoundTripper

type RateLimitedRoundTripper struct {
	// Transport allows to customize the underneath RoundTripper
	// If not provided, http.DefaultTransport will be used
	Transport http.RoundTripper
	// KeyFunc allows to group how requests will be grouped for rate limiting
	// the default behaviour returns the request method with full URL
	// ensuring that all calls to a specific endpoint will be serialized
	KeyFunc              func(req *http.Request) string
	ConcurrentCallsLimit int
	// contains filtered or unexported fields
}

RateLimitedRoundTripper ensures similar requests are serialised instead of run in parallel A tipical use is to use this in front of a caching layer to reduce the request rate to the upstream services

func (*RateLimitedRoundTripper) RoundTrip

func (t *RateLimitedRoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error)

type RoundTripperFunc

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

RoundTripperFunc implements the http.RoundTripper interface for a given function

func (RoundTripperFunc) RoundTrip

func (t RoundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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