client

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLoopback added in v0.19.0

func IsLoopback(host string) bool

IsLoopback returns true if the host is a loopback address. This includes "localhost" and IP addresses in the loopback range (127.0.0.0/8 for IPv4, ::1 for IPv6).

func WithRedirectCallback added in v0.15.0

func WithRedirectCallback(ctx context.Context, cb RedirectCallback) context.Context

WithRedirectCallback returns a context with a redirect callback.

Types

type Client

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

Client represents a wrapped HTTP client.

func NewClient

func NewClient(cfg ClientConfig) *Client

NewClient returns an initialized Client given the provided configuration.

func (*Client) Do

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

Do performs the provided http Request, returning the response.

func (*Client) HTTPClient added in v0.19.0

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying *http.Client.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, cfg RequestConfig) (*http.Request, error)

NewRequest returns an *http.Request given the provided configuration.

func (*Client) SetJar added in v0.17.0

func (c *Client) SetJar(jar http.CookieJar)

SetJar sets the cookie jar on the HTTP client.

type ClientConfig

type ClientConfig struct {
	CACerts        []*x509.Certificate
	ClientCert     *tls.Certificate
	ConnectTimeout time.Duration
	DNSServer      *url.URL
	HTTP           core.HTTPVersion
	Insecure       bool
	Proxy          *url.URL
	Redirects      *int
	TLS            uint16
	UnixSocket     string
}

ClientConfig represents the optional configuration parameters for a Client.

type RedirectCallback added in v0.15.0

type RedirectCallback func(hop RedirectHop)

RedirectCallback is called when a redirect occurs.

type RedirectHop added in v0.15.0

type RedirectHop struct {
	Request     *http.Request  // The request that triggered the redirect
	Response    *http.Response // The redirect response (e.g., 302)
	NextRequest *http.Request  // The new request about to be made
}

RedirectHop represents a single redirect in the chain.

type RequestConfig

type RequestConfig struct {
	AWSSigV4    *aws.Config
	Basic       *core.KeyVal[string]
	Bearer      string
	ContentType string
	Data        io.Reader
	Form        []core.KeyVal[string]
	Headers     []core.KeyVal[string]
	HTTP        core.HTTPVersion
	Method      string
	Multipart   *multipart.Multipart
	NoEncode    bool
	QueryParams []core.KeyVal[string]
	Range       []string
	URL         *url.URL
}

RequestConfig represents the configuration for creating an HTTP request.

type TLSDialConfig added in v0.19.0

type TLSDialConfig struct {
	CACerts    []*x509.Certificate
	ClientCert *tls.Certificate
	DNSServer  *url.URL
	Insecure   bool
	TLS        uint16
}

TLSDialConfig holds the common configuration for building a TLS config and dial function.

func (*TLSDialConfig) BuildDialContext added in v0.19.0

func (c *TLSDialConfig) BuildDialContext() func(ctx context.Context, network, address string) (net.Conn, error)

BuildDialContext returns a dial context function that uses the configured DNS server, supporting both UDP and DoH (DNS over HTTPS).

func (*TLSDialConfig) BuildDialer added in v0.19.0

func (c *TLSDialConfig) BuildDialer() *net.Dialer

BuildDialer returns a net.Dialer configured with the DNS server, if any.

func (*TLSDialConfig) BuildTLSConfig added in v0.19.0

func (c *TLSDialConfig) BuildTLSConfig() *tls.Config

BuildTLSConfig returns a *tls.Config from the common configuration fields.

Jump to

Keyboard shortcuts

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