httputil

package
v1.57.6 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 18 Imported by: 14

Documentation

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

Variables

View Source
var Pool = &PortPool{
	LastBusyPort:  13999,
	Mutex:         &sync.Mutex{},
	PortsMap:      map[int]bool{},
	PortRangeInit: 14000,
	PortRangeSize: 1000,
}

Functions

func CreateTransport added in v1.28.0

func CreateTransport(auth *config.Auth, transportConfig *http.Transport, timeout time.Duration, customHeaders map[string]string) (http.RoundTripper, error)

Creates a new HTTP Transport with TLS, Timeouts, and optional custom headers.

Please remember that setting long timeouts is not recommended as it can make idle connections stay open for as long as 2 * timeout. This should only be done in cases where you know the request is very likely going to be reused at some point in the near future.

func GetTLSConfig added in v1.31.0

func GetTLSConfig(auth *config.Auth) (*tls.Config, error)

func GuessKialiURL added in v1.19.0

func GuessKialiURL(r *http.Request) string

func HttpGet

func HttpGet(url string, auth *config.Auth, timeout time.Duration, customHeaders map[string]string, cookies []*http.Cookie) ([]byte, int, []*http.Cookie, error)

func HttpMethods added in v1.14.0

func HttpMethods() []string

func HttpPost added in v1.41.0

func HttpPost(url string, auth *config.Auth, body io.Reader, timeout time.Duration, customHeaders map[string]string) ([]byte, int, []*http.Cookie, error)

HttpPost sends an HTTP Post request to the given URL and returns the response body.

Types

type PortForwarder added in v1.38.1

type PortForwarder interface {
	Start() error
	Stop()
}

func NewPortForwarder added in v1.38.1

func NewPortForwarder(client *rest.Interface, clientConfig *rest.Config, namespace, pod, address, portMap string, writer io.Writer) (*PortForwarder, error)

type PortPool added in v1.38.1

type PortPool struct {
	// lastBusyPort is a pointer to the last free port given, therefore is in use.
	LastBusyPort int

	// mutex is the mutex used to solve concurrency problems while managing the port
	Mutex sync.Locker

	// portsMap tracks whether an specific port is busy
	// portsMap[14100] = true => means that port 14100 is busy
	// portsMap[14101] = false => means that port 14101 is free
	PortsMap map[int]bool

	// portRangeInit is the first port number managed in the pool
	PortRangeInit int

	// portRangeSize is the size of the port range.
	// for example, the pool with portRangeSize 100 and portRangeInit 14000 manages
	// the ports from 14000 to 14099.
	PortRangeSize int
}

func (*PortPool) FreePort added in v1.38.1

func (pool *PortPool) FreePort(port int)

FreePort frees the port and makes it available for being pick to use.

func (*PortPool) GetFreePort added in v1.38.1

func (pool *PortPool) GetFreePort() int

GetFreePort returns a non-busy port available within the reserved port range (14100 - 14199). The returned port is instantaneously marked as busy until is not freed using the FreePort method.

Jump to

Keyboard shortcuts

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