internal

package
v0.1.451 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnixNetwork = "unix"
	TCPNetwork  = "tcp"
)

Network names:

View Source
const (
	HTTPProtocol  = "http"
	HTTPSProtocol = "https"
	H2CProtocol   = "h2c"
)

Protocol names:

Variables

This section is empty.

Functions

func AddHeader

func AddHeader(header *http.Header, name string, value interface{})

AddHeader creates the given set of headers if needed, and then adds the given header:

func AddValue

func AddValue(query *url.Values, name string, value interface{})

AddValue creates the given set of query parameters if needed, an then adds the given parameter.

func CheckContentType added in v0.0.329

func CheckContentType(response *http.Response) error

CheckContentType checks that the content type of the given response is JSON. Note that if the content type isn't JSON this method will consume the complete body in order to generate an error message containing a summary of the content.

func CopyHeader

func CopyHeader(header http.Header) http.Header

CopyHeader creates a copy of the given set of headers.

func CopyQuery

func CopyQuery(query url.Values) url.Values

CopyQuery creates a copy of the given set of query parameters.

func CopyValues

func CopyValues(values []string) []string

CopyValues copies a slice of strings.

func SetDeadline

func SetDeadline(ctx *context.Context, cancel *context.CancelFunc, deadline time.Time)

SetDeadline creates the given context, if needed, and sets the given deadline.

func SetTimeout

func SetTimeout(ctx *context.Context, cancel *context.CancelFunc, timeout time.Duration)

SetTimeout creates the given context, if needed, and sets the given timeout.

Types

type ClientSelector added in v0.0.329

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

ClientSelector contains the information needed to create select the HTTP client to use to connect to servers using TCP or Unix sockets.

func (*ClientSelector) Close added in v0.0.329

func (s *ClientSelector) Close() error

Close closes all the connections used by all the clients created by the selector.

func (*ClientSelector) DisableKeepAlives added in v0.0.329

func (s *ClientSelector) DisableKeepAlives() bool

DisableKeepAlives retursnt the flag that indicates if HTTP keep alive is disabled.

func (*ClientSelector) Forget added in v0.0.329

func (s *ClientSelector) Forget(ctx context.Context, address *ServerAddress) error

Forget forgets the client for the given server address. This is intended for situations where a client is missbehaving, for example when it is generating protocol errors. In those situations connections may be still open but already unusable. To avoid additional errors is beter to discard the client and create a new one.

func (*ClientSelector) Insecure added in v0.0.329

func (s *ClientSelector) Insecure() bool

Insecure returns the flag that indicates if insecure communication with the server is enabled.

func (*ClientSelector) Select added in v0.0.329

func (s *ClientSelector) Select(ctx context.Context, address *ServerAddress) (client *http.Client,
	err error)

Select returns an HTTP client to use to connect to the given server address. If a client has been created previously for the server address it will be reused, otherwise it will be created.

func (*ClientSelector) TrustedCAs added in v0.0.329

func (s *ClientSelector) TrustedCAs() *x509.CertPool

TrustedCAs sets returns the certificate pool that contains the certificate authorities that are trusted by the HTTP clients.

type ClientSelectorBuilder added in v0.0.329

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

ClientSelectorBuilder contains the information and logic needed to create an HTTP client selector. Don't create instances of this type directly, use the NewClientSelector function.

func NewClientSelector added in v0.0.329

func NewClientSelector() *ClientSelectorBuilder

NewClientSelector creates a builder that can then be used to configure and create an HTTP client selector.

func (*ClientSelectorBuilder) Build added in v0.0.329

func (b *ClientSelectorBuilder) Build(ctx context.Context) (result *ClientSelector, err error)

Build uses the information stored in the builder to create a new HTTP client selector.

func (*ClientSelectorBuilder) DisableKeepAlives added in v0.0.329

func (b *ClientSelectorBuilder) DisableKeepAlives(flag bool) *ClientSelectorBuilder

DisableKeepAlives disables HTTP keep-alives with the serviers. This is unrelated to similarly named TCP keep-alives.

func (*ClientSelectorBuilder) Insecure added in v0.0.329

Insecure enables insecure communication with the servers. This disables verification of TLS certificates and host names and it isn't recommended for a production environment.

func (*ClientSelectorBuilder) Logger added in v0.0.329

Logger sets the logger that will be used by the selector and by the created HTTP clients to write messages to the log. This is mandatory.

func (*ClientSelectorBuilder) TransportWrapper added in v0.0.329

TransportWrapper adds a function that will be used to wrap the transports of the HTTP clients. If used multiple times the transport wrappers will be called in the same order that they are added.

func (*ClientSelectorBuilder) TransportWrappers added in v0.0.329

func (b *ClientSelectorBuilder) TransportWrappers(
	values ...func(http.RoundTripper) http.RoundTripper) *ClientSelectorBuilder

TransportWrappers adds a list of functions that will be used to wrap the transports of the HTTP clients.

func (*ClientSelectorBuilder) TrustedCA added in v0.0.329

func (b *ClientSelectorBuilder) TrustedCA(value interface{}) *ClientSelectorBuilder

TrustedCA sets a source that contains he certificate authorities that will be trusted by the HTTP clients. If this isn't explicitly specified then the clients will trust the certificate authorities trusted by default by the system. The value can be a *x509.CertPool or a string, anything else will cause an error when Build method is called. If it is a *x509.CertPool then the value will replace any other source given before. If it is a string then it should be the name of a PEM file. The contents of that file will be added to the previously given sources.

func (*ClientSelectorBuilder) TrustedCAs added in v0.0.329

func (b *ClientSelectorBuilder) TrustedCAs(values ...interface{}) *ClientSelectorBuilder

TrustedCAs sets a list of sources that contains he certificate authorities that will be trusted by the HTTP clients. See the documentation of the TrustedCA method for more information about the accepted values.

type ServerAddress added in v0.0.329

type ServerAddress struct {
	// Text is the original text that was passed to the ParseServerAddress function to create
	// this server address.
	Text string

	// Network is the network that should be used to connect to the server. Possible values are
	// `tcp` and `unix`.
	Network string

	// Protocol is the application protocol used to connect to the server. Possible values are
	// `http`, `https` and `h2c`.
	Protocol string

	// Host is the name of the host used to connect to the server. This will be populated only
	// even when using Unix sockets, because clients will need it in order to populate the
	// `Host` header.
	Host string

	// Port is the port number used to connect to the server. This will only be populated when
	// using TCP. When using Unix sockets it will be zero.
	Port string

	// Socket is tha nem of the path of the Unix socket used to connect to the server.
	Socket string

	// URL is the regular URL calculated from this server address. The scheme will be `http` if
	// the protocol is `http` or `h2c` and will be `https` if the protocol is https.
	URL *neturl.URL
}

ServerAddress contains a parsed URL and additional information extracted from int, like the network (tcp or unix) and the socket name (for Unix sockets).

func ParseServerAddress added in v0.0.329

func ParseServerAddress(ctx context.Context, text string) (result *ServerAddress, err error)

ParseServerAddress parses the given text as a server address. Server addresses should be URLs with this format:

network+protocol://host:port/path?network=...&protocol=...&socket=...

The `network` and `protocol` parts of the scheme are optional.

Valid values for the `network` part of the scheme are `unix` and `tcp`. If not specified the default value is `tcp`.

Valid values for the `protocol` part of the scheme are `http`, `https` and `h2c`. If not specified the default value is `http`.

The `host` is mandatory even when using Unix sockets, because it is necessary to populate the `Host` header.

The `port` part is optional. If not specified it will be 80 for HTTP and H2C and 443 for HTTPS.

When using Unix sockets the `path` part will be used as the name of the Unix socket.

The network protocol and Unix socket can alternatively be specified using the `network`, `protocol` and `socket` query parameters. This is useful specially for specifying the Unix sockets when the path of the URL has some other meaning. For example, in order to specify the OpenID token URL it is usually necessary to include a path, so to use a Unix socket it is necessary to put it in the `socket` parameter instead:

unix://my.sso.com/my/token/path?socket=/sockets/my.socket

When the Unix socket is specified in the `socket` query parameter as in the above example the URL path will be ignored.

Some examples of valid server addresses:

type TokenResponse

type TokenResponse struct {
	AccessToken      *string `json:"access_token,omitempty"`
	Error            *string `json:"error,omitempty"`
	ErrorDescription *string `json:"error_description,omitempty"`
	RefreshToken     *string `json:"refresh_token,omitempty"`
	TokenType        *string `json:"token_type,omitempty"`
}

TokenResponse is used to unmarshal the sub-set of properties JSON token responses that we need.

Jump to

Keyboard shortcuts

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