client

package
v6.2.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxHttpResponseSize = 1024 * 1024

DefaultMaxHttpResponseSize is a default maximum size of an HTTP response body that will be read. Very large or unbounded HTTP responses can cause denial-of-service, so it's good to limit how much data is read. This of course heavily depends on the use case, but 1MB is a reasonable default.

Variables

View Source
var DefaultCachingTransport http.RoundTripper

DefaultCachingTransport is a http.RoundTripper that can be used as a default transport for HTTP clients. If caching is enabled, it will cache responses according to RFC 7234. If caching is disabled, it will behave like our safe http.SafeHttpTransport.

View Source
var SafeHttpTransport *http.Transport

SafeHttpTransport is a http.Transport that can be used as a default transport for HTTP clients. It carries the strict-mode SSRF dial guard (see denyNonPublicAddr), but only that: the HTTPS requirement, the redirect-downgrade check and the response size limit live on StrictHTTPClient. Do not build a raw http.Client on this transport for outbound requests; use the New* constructors so all strict-mode protections apply.

View Source
var StrictMode bool

StrictMode is a flag that can be set to true to enable strict mode for the HTTP client.

Functions

func SetAllowedNonPublicCIDRs

func SetAllowedNonPublicCIDRs(cidrs []string) error

SetAllowedNonPublicCIDRs parses the given CIDR strings and replaces the set of non-public networks that strict mode permits. It returns an error on the first invalid CIDR, leaving the previous value unchanged.

func SetDeniedCIDRs

func SetDeniedCIDRs(cidrs []string) error

SetDeniedCIDRs parses the given CIDR strings and replaces the operator-configured part of the denied networks; the built-in cloud metadata prefixes are always retained. It returns an error on the first invalid CIDR, leaving the previous value unchanged.

Types

type CachingRoundTripper

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

CachingRoundTripper is a simple HTTP client cache for HTTP responses. It only caches GET requests (since for POST request caching, request bodies need to be cached as well), and only if the response is cacheable according to RFC 7234. It only works on expiration time and does not respect ETags headers. When the cache is full, the entries that expire first are removed to make room for new entries (since those are the first ones to be pruned any ways).

func NewCachingTransport

func NewCachingTransport(underlyingTransport http.RoundTripper, responsesCacheSize int) *CachingRoundTripper

NewCachingTransport creates a new CachingHTTPTransport with the given underlying transport and cache size.

func (*CachingRoundTripper) RoundTrip

func (r *CachingRoundTripper) RoundTrip(httpRequest *http.Request) (*http.Response, error)

type StrictHTTPClient

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

func New

func New(timeout time.Duration) *StrictHTTPClient

New creates a new HTTP client with the given timeout.

func NewWithCache

func NewWithCache(timeout time.Duration) *StrictHTTPClient

NewWithCache creates a new HTTP client with the given timeout. It uses the DefaultCachingTransport as the underlying transport.

func NewWithTLSConfig

func NewWithTLSConfig(timeout time.Duration, tlsConfig *tls.Config) *StrictHTTPClient

NewWithTLSConfig creates a new HTTP client with the given timeout and TLS configuration. It copies the http.DefaultTransport and sets the TLSClientConfig to the given tls.Config. As such, it can't be used in conjunction with the CachingRoundTripper.

func (*StrictHTTPClient) Do

func (s *StrictHTTPClient) Do(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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