httptransport

package
v0.2023.21 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthenticatingRoundTripperContextKey = authenticatingRoundTripperContextKeyType{}

Functions

func ContextWithMetrics added in v0.8.2

func ContextWithMetrics(ctx context.Context, cfg *HttpMetricCollectionConfig) context.Context

ContextWithMetrics returns a new context based on the supplied one that contains the provided metrics collection configurations. If this context is used to perform an HTTP request with the HttpMetricCollectingRoundTripper, the configured metrics will be collected.

func WithBearerToken

func WithBearerToken(ctx context.Context, bearerToken string) context.Context

WithBearerToken inserts the bearer token into the returned context which is based on the provided context. If this context is then used with the HTTP request in a client having the AuthenticatingRoundTripper as its transport, the round tripper will insert this token into the Authorization header of the request.

Types

type AuthenticatingRoundTripper

type AuthenticatingRoundTripper struct {
	http.RoundTripper
}

AuthenticatingRoundTripper is a wrapper around an HTTP round tripper that add a bearer token from the context (if any) before performing the request using the wrapped round tripper.

func (AuthenticatingRoundTripper) RoundTrip

func (r AuthenticatingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type ExaminingRoundTripper

type ExaminingRoundTripper struct {
	http.RoundTripper
	Examiner RoundTripExaminer
}

ExaminingRoundTripper is an HTTP request round tripper that calls the Examiner after the request is made so that it can examine the request and response or turn it into an error.

func (ExaminingRoundTripper) RoundTrip

func (r ExaminingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type HttpCounterMetricPicker added in v0.8.2

type HttpCounterMetricPicker interface {
	Pick(r *http.Request, resp *http.Response, err error) []prometheus.Counter
}

HttpCounterMetricPicker is an interface used by the HttpMetricCollectingRoundTripper to pick the counter metrics to collect based on the request and response. Because it is used during an HTTP round trip, the implementations of this interface must be thread-safe.

type HttpCounterMetricPickerFunc added in v0.8.2

type HttpCounterMetricPickerFunc func(*http.Request, *http.Response, error) []prometheus.Counter

HttpCounterMetricPickerFunc is a functional implementation of HttpCounterMetricPicker.

func (HttpCounterMetricPickerFunc) Pick added in v0.8.2

type HttpGaugeMetricPicker added in v0.8.2

type HttpGaugeMetricPicker interface {
	Pick(r *http.Request, resp *http.Response, err error) []prometheus.Gauge
}

HttpGaugeMetricPicker is an interface used by the HttpMetricCollectingRoundTripper to pick the gauge metrics to collect based on the request and response. Because it is used during an HTTP round trip, the implementations of this interface must be thread-safe.

type HttpGaugeMetricPickerFunc added in v0.8.2

type HttpGaugeMetricPickerFunc func(*http.Request, *http.Response, error) []prometheus.Gauge

HttpGaugeMetricPickerFunc is a functional implementation of HttpGaugeMetricPicker

func (HttpGaugeMetricPickerFunc) Pick added in v0.8.2

type HttpHistogramOrSummaryMetricPicker added in v0.8.2

type HttpHistogramOrSummaryMetricPicker interface {
	Pick(r *http.Request, resp *http.Response, err error) []prometheus.Observer
}

HttpHistogramOrSummaryMetricPicker is an interface used by the HttpMetricCollectingRoundTripper to pick the histogram or summary metrics to collect based on the request and response. Because it is used during an HTTP round trip, the implementations of this interface must be thread-safe.

type HttpHistogramOrSummaryMetricPickerFunc added in v0.8.2

type HttpHistogramOrSummaryMetricPickerFunc func(*http.Request, *http.Response, error) []prometheus.Observer

HttpHistogramOrSummaryMetricPickerFunc is a functional implementation of HttpHistogramOrSummaryMetricPicker.

func (HttpHistogramOrSummaryMetricPickerFunc) Pick added in v0.8.2

type HttpMetricCollectingRoundTripper added in v0.8.2

type HttpMetricCollectingRoundTripper struct {
	http.RoundTripper
}

HttpMetricCollectingRoundTripper is a wrapper around http.RoundTripper interface that, given an HttpMetricCollectionConfig, collects the metrics for each HTTP request processed. The metric collection configuration is passed to the roundtripper by injecting it into a context, so it can differ per request.

func (HttpMetricCollectingRoundTripper) RoundTrip added in v0.8.2

func (h HttpMetricCollectingRoundTripper) RoundTrip(request *http.Request) (*http.Response, error)

type HttpMetricCollectionConfig added in v0.8.2

type HttpMetricCollectionConfig struct {
	GaugePicker              HttpGaugeMetricPicker
	CounterPicker            HttpCounterMetricPicker
	HistogramOrSummaryPicker HttpHistogramOrSummaryMetricPicker
}

HttpMetricCollectionConfig specifies what metric should be collected.

type RoundTripExaminer

type RoundTripExaminer interface {
	Examine(req *http.Request, response *http.Response) error
}

RoundTripExaminer is interface enabling the implementors to examine the request and response during the roundtrip and potentially somehow modify them or turn them into error.

type RoundTripExaminerFunc

type RoundTripExaminerFunc func(*http.Request, *http.Response) error

RoundTripExaminerFunc is a conversion of a function into RoundTripExaminer

func (RoundTripExaminerFunc) Examine

func (r RoundTripExaminerFunc) Examine(req *http.Request, res *http.Response) error

Jump to

Keyboard shortcuts

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