httpclient

package
v0.0.85-test Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrResponseBodyTooLarge = errors.New("http: response body too large")

ErrResponseBodyTooLarge indicates response body is too large

Functions

func CountBytesReader

func CountBytesReader(reader io.ReadCloser, callback CloseCallbackFunc) io.ReadCloser

CountBytesReader counts the total amount of bytes read from the underlying reader.

The provided callback func will be called before the underlying reader is closed.

func MaxBytesReader

func MaxBytesReader(r io.ReadCloser, n int64) io.ReadCloser

MaxBytesReader is similar to io.LimitReader but is intended for limiting the size of incoming request bodies. In contrast to io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a non-EOF error for a Read beyond the limit, and closes the underlying reader when its Close method is called.

MaxBytesReader prevents clients from accidentally or maliciously sending a large request and wasting server resources.

func NewProvider

func NewProvider(opts ...httpclient.ProviderOptions) *httpclient.Provider

NewProvider creates a new HTTP client provider. Optionally provide ProviderOptions options that will be used as default if not specified in Options argument to Provider.New, Provider.GetTransport and Provider.GetTLSConfig. If no middlewares are provided in opts the DefaultMiddlewares() will be used. If you provide middlewares you have to manually add the DefaultMiddlewares() for it to be enabled. Note: Middlewares will be executed in the same order as provided.

Types

type CloseCallbackFunc

type CloseCallbackFunc func(bytesRead int64)

type Provider

type Provider interface {
	// New creates a new http.Client given provided options.
	New(opts ...httpclient.Options) (*http.Client, error)

	// GetTransport creates a new http.RoundTripper given provided options.
	GetTransport(opts ...httpclient.Options) (http.RoundTripper, error)

	// GetTLSConfig creates a new tls.Config given provided options.
	GetTLSConfig(opts ...httpclient.Options) (*tls.Config, error)
}

Provider provides abilities to create http.Client, http.RoundTripper and tls.Config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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