xhttpclient

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC SPDX-License-Identifier: Apache-2.0

SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC SPDX-License-Identifier: Apache-2.0

SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC SPDX-License-Identifier: Apache-2.0

SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRoundTripper

func NewRoundTripper(t *Transport) http.RoundTripper

NewRoundTripper creates an http.RoundTripper from a set of Transport options. If the Transport is nil, this function returns a default http.Transport instance. Otherwise, an http.Transport is returned with its fields set from the given Transport options.

func NewTlsConfig

func NewTlsConfig(tc *Tls) *tls.Config

NewTlsConfig assembles a *tls.Config for clients given a set of configuration options. If the Tls options is nil, this method returns nil, nil.

Types

type Chain

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

Chain is a sequence of Constructors, just like github.com/justinas/alice.Chain

func NewChain

func NewChain(c ...Constructor) Chain

func (Chain) Append

func (ch Chain) Append(more ...Constructor) Chain

func (Chain) Extend

func (ch Chain) Extend(more Chain) Chain

func (Chain) Then

func (ch Chain) Then(rt http.RoundTripper) http.RoundTripper

func (Chain) ThenFunc

func (ch Chain) ThenFunc(rtf RoundTripperFunc) http.RoundTripper

type ChainFactory added in v0.0.3

type ChainFactory interface {
	NewClientChain(string, Options) (Chain, error)
}

A ChainFactory can be used to tailor a Chain of decorators for a specific client. This factory type is primarily useful when an application has multiple HTTP client objects. For cases where there is only (1) HTTP client, a Chain component works better.

type ChainFactoryFunc added in v0.0.3

type ChainFactoryFunc func(string, Options) (Chain, error)

func (ChainFactoryFunc) NewClientChain added in v0.0.3

func (cff ChainFactoryFunc) NewClientChain(name string, o Options) (Chain, error)

type ClientUnmarshalIn

type ClientUnmarshalIn struct {
	fx.In

	// Unmarshaller is the required configuration unmarshalling component
	Unmarshaller config.Unmarshaller

	// Chain is an optional component.  If present in the application, this chain
	// will be used to decorate the roundtripper.  Any constructors set via Unmarshal
	// will be appended to this chain.  This field and ChainFactory can be used together, and both
	// will be used to produce a merged Chain if both fields are set.
	//
	// Using this component allows for global decorators that apply to all clients.
	Chain Chain `optional:"true"`

	// ChainFactory is an optional component used to create a Chain specific to a given HTTP client.
	// Both this field and Chain may be set, in which case both are used to create a single Chain.
	ChainFactory ChainFactory `optional:"true"`

	// RoundTripper is an optional http.RoundTripper component.  If present, this field will be used
	// for clients unmarshalled by this instance.  Configuration will be ignored in favor of this component.
	RoundTripper http.RoundTripper `optional:"true"`

	// Tracing will be used to set up tracing instrumentation code.
	Tracing candlelight.Tracing `optional:"true"`
}

ClientUnmarshalIn defines the set of dependencies for an HTTP client

type Constructor

type Constructor func(http.RoundTripper) http.RoundTripper

Constructor is an Alice-style constructor for RoundTrippers

type Interface

type Interface interface {
	Do(*http.Request) (*http.Response, error)
}

Interface defines the behavior of an HTTP client. *http.Client implements this interface.

func New

func New(o Options) Interface

New fully constructs an http client from a set of options. NewRoundTripper is used to create the http.RoundTripper.

func NewCustom added in v0.0.3

func NewCustom(o Options, rt http.RoundTripper) Interface

NewCustom uses a set of options and a supplied RoundTripper to create an http client. Use this function when a custom RoundTripper, including decoration, is desired.

type Options

type Options struct {
	// Timeout is the http.Client timeout
	Timeout time.Duration

	// Header is an optional set of HTTP headers applied to all outgoing requests
	// made through any client created with these options.
	Header http.Header

	// Transport describes the http.Transport created for this client when a custom
	// RoundTripper is not supplied.  If this is unset, a default http.Transport is created.
	Transport *Transport
}

Options represents the set of configurable options for an HTTP client

type RequestHeaders

type RequestHeaders struct {
	Header http.Header
}

RequestHeaders provides a RoundTripper constructor that inserts a constant set of headers into each request

func (RequestHeaders) Then

func (RequestHeaders) ThenFunc

type RoundTripperFunc

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

func (RoundTripperFunc) RoundTrip

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

type Tls

type Tls struct {
	InsecureSkipVerify bool
}

Tls represents the set of configurable options for client-side TLS

type Transport

type Transport struct {
	DisableKeepAlives      bool
	DisableCompression     bool
	MaxIdleConns           int
	MaxIdleConnsPerHost    int
	MaxConnsPerHost        int
	IdleConnTimeout        time.Duration
	ResponseHeaderTimeout  time.Duration
	ExpectContinueTimeout  time.Duration
	MaxResponseHeaderBytes int64
	TlsHandshakeTimeout    time.Duration
	Tls                    *Tls
}

Transport represents the set of configurable options for a client RoundTripper The majority of these fields map directory to an http.Transport. See https://godoc.org/net/http#Transport

type Unmarshal

type Unmarshal struct {
	// Key is the required configuration key unmarshalled via Viper.  This key is unmarshalled as an Options.
	Key string

	// Name is the optional name of this client within the application.  If unset, the Key is used.  This
	// field is used when providing a named client component via Annotated.
	Name string

	// Chain is an optional decoration for the client's RoundTripper.  This field is used for decoration
	// initialized outside the uber/fx application.
	Chain Chain
}

Unmarshal encompasses all the non-component information for unmarshalling and instantiating an HTTP client.

func (Unmarshal) Annotated added in v0.0.3

func (u Unmarshal) Annotated() fx.Annotated

Annotated returns an uber/fx Annotated instance that emits an HTTP client with a specific name. The Name field is used if set, otherwise Key is used. If multiple HTTP clients are needed for the enclosing application, use this function to emit them as named components.

func (Unmarshal) Provide added in v0.0.3

func (u Unmarshal) Provide(in ClientUnmarshalIn) (Interface, error)

Provide emits an HTTP client as an unnamed component. If only (1) client is needed for the entire application, this method is best.

Jump to

Keyboard shortcuts

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