Documentation
¶
Overview ¶
Package httpclient is a hardened, framework-free *http.Client factory. It wires the shared client middleware from gitlab.com/phpboyscout/go/transit (retry, circuit breaking, auth, logging) and the hardened TLS defaults from gitlab.com/phpboyscout/go/tls onto the standard library net/http client, with a secure-by-default posture: TLS 1.2 floor, curated connection limits and timeouts, and a redirect policy that refuses HTTPS→HTTP downgrades.
It is the client half of the transport stack extracted from go-tool-base — a consumer that only makes outbound HTTP calls never inherits the server stack (controls, authn, gateway).
Index ¶
- func NewClient(opts ...ClientOption) *http.Client
- func NewTransport(tlsCfg *tls.Config) *http.Transport
- type ClientOption
- func WithCertPool(pool *x509.CertPool) ClientOption
- func WithClientMiddleware(chain transithttp.ClientChain) ClientOption
- func WithMaxRedirects(n int) ClientOption
- func WithRetry(cfg transithttp.RetryConfig) ClientOption
- func WithSensitiveHeaders(names ...string) ClientOption
- func WithTLSConfig(cfg *tls.Config) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- func WithTransport(rt http.RoundTripper) ClientOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(opts ...ClientOption) *http.Client
NewClient returns an *http.Client with security-focused defaults: TLS 1.2 minimum, curated cipher suites, timeouts, connection limits, and redirect policy that rejects HTTPS-to-HTTP downgrades.
Types ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption configures the secure HTTP client.
func WithCertPool ¶
func WithCertPool(pool *x509.CertPool) ClientOption
WithCertPool sets the root CA pool used to verify server certificates, preserving the hardened default TLS configuration (cipher suites, minimum version, curve preferences). Use this to trust certificates that are not in the system roots, such as a private CA or self-signed cert. Build the pool with tls.CertPool. Applying WithTLSConfig after this option replaces the pool along with the rest of the TLS configuration.
func WithClientMiddleware ¶
func WithClientMiddleware(chain transithttp.ClientChain) ClientOption
WithClientMiddleware applies a transit client middleware chain to the client's transport. The chain wraps the transport after retry (if configured) so that retry operates on the raw transport, not on logged/authed requests.
func WithMaxRedirects ¶
func WithMaxRedirects(n int) ClientOption
WithMaxRedirects sets the maximum number of redirects to follow. Default: 10. Set to 0 to disable redirect following entirely.
func WithRetry ¶
func WithRetry(cfg transithttp.RetryConfig) ClientOption
WithRetry enables automatic retry with exponential backoff for transient failures, using the retry transport from gitlab.com/phpboyscout/go/transit.
func WithSensitiveHeaders ¶ added in v0.1.2
func WithSensitiveHeaders(names ...string) ClientOption
WithSensitiveHeaders names request headers that carry credentials. On any redirect that leaves the origin (scheme, host or port) of the *initial* request, the named headers are removed before the hop is followed. The standard library already does this for Authorization, Www-Authenticate, Cookie and Cookie2; this option extends the same semantics to custom credential headers such as PRIVATE-TOKEN or X-Api-Key, which the stdlib copies to every hop. Same-origin redirects retain the headers. The option is opt-in: without it, redirect header handling is unchanged.
func WithTLSConfig ¶
func WithTLSConfig(cfg *tls.Config) ClientOption
WithTLSConfig overrides the default TLS configuration. The caller is responsible for ensuring the provided config meets security requirements.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the overall request timeout. Default: 30s.
func WithTransport ¶
func WithTransport(rt http.RoundTripper) ClientOption
WithTransport overrides the entire HTTP transport. When set, transport-level options (TLS config, connection limits) are ignored.