transport

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 23 Imported by: 0

README

HTTP Transports

HTTP Transport to be used with the http client from go.

Environment based configuration

  • HTTP_TRANSPORT_DUMP default: "" (option values are comma separated)
    • Can contain a list of logging options:
      • request will log the complete request with headers human readable
      • response will log the complete response with headers human readable
      • request-hex will log the complete request with headers in HEX
      • response-hex will log the complete response with headers in HEX
      • body will enable logging of the body for hex and human readable outputs
    • Simple request header logging may look like this request,response
    • Full human readable logging may look like this request,response,body
    • Complete logging may look like this request,response,request-hex,response-hex,body

Documentation

Index

Constants

View Source
const (
	DumpRoundTripperOptionRequest     = "request"
	DumpRoundTripperOptionResponse    = "response"
	DumpRoundTripperOptionRequestHEX  = "request-hex"
	DumpRoundTripperOptionResponseHEX = "response-hex"
	DumpRoundTripperOptionBody        = "body"
	DumpRoundTripperOptionNoRedact    = "no-redact"
)

Variables

View Source
var (
	ErrRetryFailed   = errors.New("failed after maximum number of retries")
	ErrCircuitBroken = errors.New("circuit to remote host is open")
)

Functions

func CtxWithDumpRoundTripperOptions added in v0.4.10

func CtxWithDumpRoundTripperOptions(ctx context.Context, opts DumpOptions) context.Context

func NewCircuitBreakerTripper added in v0.1.26

func NewCircuitBreakerTripper(settings gobreaker.Settings) *circuitBreakerTripper

func NewDefaultCircuitBreakerTripper added in v0.1.26

func NewDefaultCircuitBreakerTripper(name string) *circuitBreakerTripper

func NewDefaultRetryTransport added in v0.1.13

func NewDefaultRetryTransport() *rehttp.Transport

NewDefaultRetryTransport returns a new default retry transport.

func RetryEOFErr added in v0.4.4

func RetryEOFErr() rehttp.RetryFn

RetryEOFErr retries only when the error is EOF

func RetryNetErr added in v0.4.4

func RetryNetErr() rehttp.RetryFn

RetryNetErr retries errors returned by the 'net' package.

Types

type ChainableRoundTripper

type ChainableRoundTripper interface {
	http.RoundTripper

	// Transport returns the RoundTripper to make HTTP requests
	Transport() http.RoundTripper
	// SetTransport sets the RoundTripper to make HTTP requests
	SetTransport(http.RoundTripper)
}

ChainableRoundTripper models a chainable round tripper

type DumpOption added in v0.4.10

type DumpOption func(o DumpOptions) error

func WithDumpOption added in v0.4.10

func WithDumpOption(option string, enabled bool) DumpOption

type DumpOptions added in v0.4.10

type DumpOptions map[string]bool

func DumpRoundTripperOptionsFromCtx added in v0.4.10

func DumpRoundTripperOptionsFromCtx(ctx context.Context) DumpOptions

func NewDumpOptions added in v0.4.10

func NewDumpOptions(opts ...DumpOption) (DumpOptions, error)

func (DumpOptions) AnyEnabled added in v0.4.10

func (o DumpOptions) AnyEnabled(options ...string) bool

func (DumpOptions) IsEnabled added in v0.4.10

func (o DumpOptions) IsEnabled(option string) bool

type DumpRoundTripper added in v0.1.52

type DumpRoundTripper struct {
	// contains filtered or unexported fields
}

DumpRoundTripper dumps requests and responses in one log event. This is not part of te request logger to be able to filter dumps more easily

func NewDumpRoundTripper added in v0.1.52

func NewDumpRoundTripper(options ...DumpRoundTripperOption) (*DumpRoundTripper, error)

NewDumpRoundTripper return the roundtripper with configured options

func NewDumpRoundTripperEnv added in v0.1.52

func NewDumpRoundTripperEnv() *DumpRoundTripper

NewDumpRoundTripperEnv creates a new RoundTripper based on the configuration that is passed via environment variables

func (*DumpRoundTripper) AnyEnabled added in v0.1.52

func (l *DumpRoundTripper) AnyEnabled() bool

AnyEnabled returns true if any logging is enabled

func (*DumpRoundTripper) ContainsBlacklistedPrefix added in v0.2.5

func (l *DumpRoundTripper) ContainsBlacklistedPrefix(url *url.URL, blacklist []string) bool

func (*DumpRoundTripper) RoundTrip added in v0.1.52

func (l *DumpRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction via Transport()

func (*DumpRoundTripper) SetTransport added in v0.1.52

func (l *DumpRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*DumpRoundTripper) Transport added in v0.1.52

func (l *DumpRoundTripper) Transport() http.RoundTripper

Transport returns the RoundTripper to make HTTP requests

type DumpRoundTripperOption added in v0.1.52

type DumpRoundTripperOption func(rt *DumpRoundTripper) (*DumpRoundTripper, error)

func RoundTripConfig added in v0.2.5

func RoundTripConfig(dumpOptions ...string) DumpRoundTripperOption

type ExternalDependencyRoundTripper added in v0.1.82

type ExternalDependencyRoundTripper struct {
	// contains filtered or unexported fields
}

ExternalDependencyRoundTripper greps external dependency headers and attach them to the currect context

func NewExternalDependencyRoundTripper added in v0.1.100

func NewExternalDependencyRoundTripper(name string) *ExternalDependencyRoundTripper

func (*ExternalDependencyRoundTripper) RoundTrip added in v0.1.82

RoundTrip executes a single HTTP transaction via Transport()

func (*ExternalDependencyRoundTripper) SetTransport added in v0.1.82

func (l *ExternalDependencyRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*ExternalDependencyRoundTripper) Transport added in v0.1.82

Transport returns the RoundTripper to make HTTP requests

type JaegerRoundTripper

type JaegerRoundTripper struct {
	// contains filtered or unexported fields
}

JaegerRoundTripper implements a chainable round tripper for tracing

func (*JaegerRoundTripper) RoundTrip

func (l *JaegerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a HTTP request with distributed tracing

func (*JaegerRoundTripper) SetTransport

func (l *JaegerRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*JaegerRoundTripper) Transport

func (l *JaegerRoundTripper) Transport() http.RoundTripper

Transport returns the RoundTripper to make HTTP requests

type LocaleRoundTripper added in v0.1.42

type LocaleRoundTripper struct {
	// contains filtered or unexported fields
}

LocaleRoundTripper implements a chainable round tripper for locale forwarding

func (*LocaleRoundTripper) RoundTrip added in v0.1.42

func (l *LocaleRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a HTTP request with logging

func (*LocaleRoundTripper) SetTransport added in v0.1.42

func (l *LocaleRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*LocaleRoundTripper) Transport added in v0.1.42

func (l *LocaleRoundTripper) Transport() http.RoundTripper

Transport returns the RoundTripper to make HTTP requests

type LoggingRoundTripper

type LoggingRoundTripper struct {
	// contains filtered or unexported fields
}

LoggingRoundTripper implements a chainable round tripper for logging

func (*LoggingRoundTripper) RoundTrip

func (l *LoggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a HTTP request with logging

func (*LoggingRoundTripper) SetTransport

func (l *LoggingRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*LoggingRoundTripper) Transport

func (l *LoggingRoundTripper) Transport() http.RoundTripper

Transport returns the RoundTripper to make HTTP requests

type RequestIDRoundTripper added in v0.1.49

type RequestIDRoundTripper struct {
	SourceName string
	// contains filtered or unexported fields
}

RequestIDRoundTripper implements a chainable round tripper for setting the Request-Source header

func (*RequestIDRoundTripper) RoundTrip added in v0.1.49

func (l *RequestIDRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction via Transport()

func (*RequestIDRoundTripper) SetTransport added in v0.1.49

func (l *RequestIDRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*RequestIDRoundTripper) Transport added in v0.1.49

func (l *RequestIDRoundTripper) Transport() http.RoundTripper

Transport returns the RoundTripper to make HTTP requests

type RequestSourceRoundTripper added in v0.1.12

type RequestSourceRoundTripper struct {
	SourceName string
	// contains filtered or unexported fields
}

RequestSourceRoundTripper implements a chainable round tripper for setting the Request-Source header

func (*RequestSourceRoundTripper) RoundTrip added in v0.1.12

func (l *RequestSourceRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction via Transport()

func (*RequestSourceRoundTripper) SetTransport added in v0.1.12

func (l *RequestSourceRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*RequestSourceRoundTripper) Transport added in v0.1.12

Transport returns the RoundTripper to make HTTP requests

type RetryRoundTripper

type RetryRoundTripper struct {
	// contains filtered or unexported fields
}

RetryRoundTripper implements a chainable round tripper for retrying requests

func NewDefaultRetryRoundTripper

func NewDefaultRetryRoundTripper() *RetryRoundTripper

NewDefaultRetryRoundTripper returns a retry round tripper with a NewDefaultRetryTransport() as transport.

func NewRetryRoundTripper

func NewRetryRoundTripper(rt *rehttp.Transport) *RetryRoundTripper

NewRetryRoundTripper returns a retry round tripper with the specified retry transport.

func (*RetryRoundTripper) RoundTrip

func (l *RetryRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a HTTP request with retrying

func (*RetryRoundTripper) SetTransport

func (l *RetryRoundTripper) SetTransport(rt http.RoundTripper)

SetTransport sets the RoundTripper to make HTTP requests

func (*RetryRoundTripper) Transport

func (l *RetryRoundTripper) Transport() http.RoundTripper

Transport returns the RoundTripper to make HTTP requests

type RoundTripperChain

type RoundTripperChain struct {
	// contains filtered or unexported fields
}

RoundTripperChain chains multiple chainable round trippers together.

func Chain

Chain returns a round tripper chain with the specified chainable round trippers and http.DefaultTransport as transport. The transport can be overriden by using the Final method.

func NewDefaultTransportChain

func NewDefaultTransportChain() *RoundTripperChain

NewDefaultTransportChain returns a transport chain with retry, jaeger and logging support. If not explicitly finalized via `Final` it uses `http.DefaultTransport` as finalizer.

func NewDefaultTransportChainWithExternalName added in v0.1.82

func NewDefaultTransportChainWithExternalName(name string) *RoundTripperChain

NewDefaultTransportChain returns a transport chain with retry, jaeger and logging support. If not explicitly finalized via `Final` it uses `http.DefaultTransport` as finalizer. The passed name is recorded as external dependency

func (*RoundTripperChain) Final

Final sets the transport of the round tripper chain, which is used to make the actual request. Final should be called at the end of the chain. If not called, http.DefaultTransport is used. It returns the finalized round tripper chain.

func (*RoundTripperChain) RoundTrip

func (c *RoundTripperChain) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip calls all round trippers in the chain before executing the request.

func (*RoundTripperChain) Use

Use adds a chainable round tripper to the round tripper chain. It returns the updated round tripper chain.

Jump to

Keyboard shortcuts

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