http

package module
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 8

Documentation

Overview

Package http provides utilities to perform HTTP requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHTTPTransport

func CreateHTTPTransport(cfg pkgconfigmodel.Reader) *http.Transport

CreateHTTPTransport creates an *http.Transport for use in the agent

func Get

func Get(ctx context.Context, URL string, headers map[string]string, timeout time.Duration, cfg pkgconfigmodel.Reader) (string, error)

Get is a high level helper to query an URL and return its body as a string

func GetNumberOfWarnings

func GetNumberOfWarnings() int

GetNumberOfWarnings returns the total number of warnings

func GetProxyChangedWarnings

func GetProxyChangedWarnings() []string

GetProxyChangedWarnings returns the list of URL whose proxy behavior will change in the future

func GetProxyIgnoredWarnings

func GetProxyIgnoredWarnings() []string

GetProxyIgnoredWarnings returns the list of URL which will ignore the proxy in the future

func GetProxyTransportFunc

func GetProxyTransportFunc(p *pkgconfigmodel.Proxy, cfg pkgconfigmodel.Reader) func(*http.Request) (*url.URL, error)

GetProxyTransportFunc return a proxy function for a http.Transport that would return the right proxy depending on the configuration.

func GetProxyUsedInFutureWarnings

func GetProxyUsedInFutureWarnings() []string

GetProxyUsedInFutureWarnings returns the list of URL which will use a proxy in the future

func Put

func Put(ctx context.Context, URL string, headers map[string]string, body []byte, timeout time.Duration, cfg pkgconfigmodel.Reader) (string, error)

Put is a high level helper to query an URL using the PUT method and return its body as a string

Types

type APIToken

type APIToken struct {
	Value          string
	ExpirationDate time.Time

	sync.RWMutex
	// contains filtered or unexported fields
}

APIToken is an API token with auto renew when expired

func NewAPIToken

func NewAPIToken(cb APITokenRenewCallback) *APIToken

NewAPIToken returns a new APIToken

func (*APIToken) Get

func (token *APIToken) Get(ctx context.Context) (string, error)

Get returns the token value

type APITokenRenewCallback

type APITokenRenewCallback func(context.Context) (string, time.Time, error)

APITokenRenewCallback represents the callback type to fetch a token

type ResetClient

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

ResetClient wraps (http.Client).Do and resets the underlying connections at the configured interval

func NewResetClient

func NewResetClient(resetInterval time.Duration, httpClientFactory func() *http.Client) *ResetClient

NewResetClient returns an initialized Client resetting connections at the passed resetInterval ("0" means that no reset is performed). The underlying http.Client used will be created using the passed http client factory.

func (*ResetClient) Do

func (c *ResetClient) Do(req *http.Request) (*http.Response, error)

Do wraps (http.Client).Do. Thread safe.

Jump to

Keyboard shortcuts

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