http

package
v1.22.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 17 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthStyleAutoDetect = middlewares.AuthStyleAutoDetect
View Source
var AuthStyleInHeader = middlewares.AuthStyleInHeader
View Source
var AuthStyleInParams = middlewares.AuthStyleInParams
View Source
var TraceAll = TraceConfig{
	MaxBodyLength:   4096,
	Body:            true,
	Response:        true,
	QueryParam:      true,
	Headers:         true,
	ResponseHeaders: true,
	TLS:             true,
}
View Source
var TraceHeaders = TraceConfig{
	Body:            false,
	Response:        false,
	QueryParam:      true,
	Headers:         true,
	ResponseHeaders: true,
	TLS:             false,
}

Functions

func Error added in v1.13.0

func Error(span trace.Span, err error) bool

Types

type AuthConfig added in v1.13.0

type AuthConfig struct {
	// Username for basic Auth
	Username string

	// Password for basic Auth
	Password string

	// Ntlm controls whether to use NTLM
	Ntlm bool

	// Ntlmv2 controls whether to use NTLMv2
	Ntlmv2 bool
}

func (*AuthConfig) IsEmpty added in v1.16.0

func (a *AuthConfig) IsEmpty() bool

type Client

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

Client is a type that represents an HTTP client

func NewClient

func NewClient() *Client

NewClient configures a new HTTP client using given configuration

func (*Client) Auth added in v1.13.0

func (c *Client) Auth(username, password string) *Client

Auth sets up the username & password for basic auth or NTLM.

func (*Client) BaseURL added in v1.13.0

func (c *Client) BaseURL(url string) *Client

func (*Client) CacheDNS added in v1.13.0

func (c *Client) CacheDNS(val bool) *Client

func (*Client) ConnectTo added in v1.13.0

func (c *Client) ConnectTo(host string) *Client

ConnectTo specifies the host:port on which the URL is sought. If empty, the URL's host is used.

func (*Client) DisableKeepAlive added in v1.13.0

func (c *Client) DisableKeepAlive(val bool) *Client

DisableKeepAlives prevents reuse of TCP connections

func (*Client) Header added in v1.13.0

func (c *Client) Header(key, val string) *Client

func (*Client) InsecureSkipVerify added in v1.13.0

func (c *Client) InsecureSkipVerify(val bool) *Client

InsecureSkipVerify controls whether a client verifies the server's certificate chain and host name

func (*Client) NTLM added in v1.13.0

func (c *Client) NTLM(val bool) *Client

func (*Client) NTLMV2 added in v1.13.0

func (c *Client) NTLMV2(val bool) *Client

func (*Client) OAuth added in v1.15.0

func (c *Client) OAuth(config middlewares.OauthConfig) *Client

func (*Client) Proxy added in v1.13.0

func (c *Client) Proxy(url string) *Client

func (*Client) R added in v1.13.0

func (c *Client) R(ctx context.Context) *Request

R create a new request.

func (*Client) Retry added in v1.13.0

func (c *Client) Retry(maxRetries uint, baseDuration time.Duration, exponent float64) *Client

Retry configuration retrying on failure with exponential backoff.

Base duration of a second & an exponent of 2 is a good option.

func (*Client) Timeout added in v1.13.0

func (c *Client) Timeout(d time.Duration) *Client

Timeout specifies a time limit for requests made by this Client.

Default: 2 minutes

func (*Client) Trace added in v1.15.0

func (c *Client) Trace(config TraceConfig) *Client

func (*Client) TraceToStdout added in v1.16.0

func (c *Client) TraceToStdout(config TraceConfig) *Client

func (*Client) Use added in v1.13.0

func (c *Client) Use(middlewares ...middlewares.Middleware) *Client

Use adds middleware to the client that wraps the client's transport

func (*Client) UserAgent added in v1.16.0

func (c *Client) UserAgent(agent string) *Client

type OauthConfig added in v1.17.0

type OauthConfig = middlewares.OauthConfig

type Request

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

func (*Request) Body added in v1.13.0

func (r *Request) Body(v any) error

Body sets the request body

func (*Request) Delete added in v1.13.0

func (r *Request) Delete(url string) (*Response, error)

func (*Request) Do added in v1.13.0

func (r *Request) Do(method, reqURL string) (resp *Response, err error)

Do performs an HTTP request with the specified method and URL.

func (*Request) Get added in v1.13.0

func (r *Request) Get(url string) (*Response, error)

func (*Request) GetHeader added in v1.20.1

func (r *Request) GetHeader(key string) string

func (*Request) GetHeaders added in v1.16.0

func (r *Request) GetHeaders() map[string]string

func (*Request) Header added in v1.13.0

func (r *Request) Header(key, value string) *Request

Header set a header for the request.

func (*Request) Patch added in v1.13.0

func (r *Request) Patch(url string, body any) (*Response, error)

func (*Request) Post added in v1.13.0

func (r *Request) Post(url string, body any) (*Response, error)

func (*Request) Put added in v1.13.0

func (r *Request) Put(url string, body any) (*Response, error)

func (*Request) QueryParam added in v1.13.0

func (r *Request) QueryParam(key, value string) *Request

QueryParam sets query params

func (*Request) Retry added in v1.13.0

func (r *Request) Retry(maxRetries uint, baseDuration time.Duration, exponent float64) *Request

Retry configuration retrying on failure with exponential backoff.

Base duration of a second & an exponent of 2 is a good option.

type Response

type Response struct {
	// The underlying http.Response is embed into Response.
	*http.Response

	// Request is the Response's related Request.
	Request *Request
}

Response extends the stdlib http.Response type and extends its functionality

func (*Response) AsJSON added in v1.13.0

func (h *Response) AsJSON() (map[string]any, error)

func (*Response) AsString

func (r *Response) AsString() (string, error)

func (*Response) GetHeaders added in v1.16.0

func (r *Response) GetHeaders() map[string]string

func (*Response) GetSSLAge added in v1.13.0

func (h *Response) GetSSLAge() *time.Duration

func (*Response) Into added in v1.13.0

func (r *Response) Into(dest any) error

func (*Response) IsJSON added in v1.13.0

func (h *Response) IsJSON() bool

func (*Response) IsOK

func (r *Response) IsOK(responseCodes ...int) bool

IsOK is a convenience method to determine if the response returned a 200 OK

type RetryConfig added in v1.13.0

type RetryConfig struct {
	// Number of retries to attempt
	MaxRetries uint

	// RetryWait specifies the base wait duration between retries
	RetryWait time.Duration

	// Amount to increase RetryWait with each failure, 2.0 is a good option for exponential backoff
	Factor float64
}

type TraceConfig added in v1.15.0

type TraceConfig = middlewares.TraceConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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