Skip to content

Configuration ​

Config ​

go
type Config struct {
    Timeouts   TimeoutConfig
    Connection ConnectionConfig
    Security   SecurityConfig
    Retry      RetryConfig
    Middleware MiddlewareConfig
    Defaults   RequestDefaults
}

The main configuration struct; the five sub-configs and Defaults are all value types. Use DefaultConfig() to obtain secure defaults — the returned Config can have its fields modified directly.

FieldTypeDescription
Config.TimeoutsTimeoutConfigRequest/dial/TLS-handshake/response-header/idle-connection timeouts
Config.ConnectionConnectionConfigConnection pooling, proxies, HTTP/2, cookies, and DNS-over-HTTPS
Config.SecuritySecurityConfigTLS, validation, and SSRF protection
Config.RetryRetryConfigAutomatic retries of transient failures
Config.MiddlewareMiddlewareConfigPer-client middleware chain
Config.DefaultsRequestDefaultsPer-request defaults (User-Agent, default headers, redirect policy)
go
cfg := httpc.DefaultConfig()
cfg.Timeouts.Request = 60 * time.Second
cfg.Retry.MaxRetries = 5
client, err := httpc.New(cfg)

New() deep-copies the Config internally (including the Defaults.Headers map and the Middleware.Middlewares slice), so modifying the original cfg after the client is created does not affect its behavior. Two exceptions are shared by reference: Retry.CustomPolicy and Security.CertificatePinner are not deep-copied — pinner implementations are expected to be concurrency-safe, but if your custom retry policy carries mutable state, do not pass the same Config instance concurrently to multiple New() calls.

Related types

For request-level fine-grained control use the RequestOption function options (see Request Options); to customize retry decisions, implement the RetryPolicy interface.

TimeoutConfig ​

go
type TimeoutConfig struct {
    Request        time.Duration // Total request timeout (including retries), default 180s
    Dial           time.Duration // TCP connection timeout, default 10s
    TLSHandshake   time.Duration // TLS handshake timeout, default 10s
    ResponseHeader time.Duration // Wait-for-response-header timeout, default 0 (disabled, relies on context timeout)
    IdleConn       time.Duration // Idle-connection keep-alive time, default 90s
}
FieldDefaultMaximum
Request180s30min
Dial10s30min
TLSHandshake10s30min
ResponseHeader030min
IdleConn90s30min

Setting a field to 0 means no timeout (not recommended for production).

ResponseHeader design

ResponseHeader defaults to 0 (disabled). In this case TimeoutConfig.Request or WithTimeout() serves as the sole timeout mechanism, ensuring WithTimeout() has full control over request duration. This design suits AI APIs, long polling, and other scenarios that need extended response times. Set it to a positive value only when you need a transport-layer hard cap (e.g. to defend against Slowloris attacks), but note: this timeout takes effect at the Transport layer, applies to all requests sharing the same client, and fires early when it is shorter than the deadline set by WithTimeout.

ProxyStrategy ​

go
type ProxyStrategy = proxypool.Strategy

const (
    ProxyStrategyRoundRobin = proxypool.StrategyRoundRobin // Round-robin (default)
    ProxyStrategyRandom     = proxypool.StrategyRandom     // Random
)

Proxy-pool selection strategy.

ConstantDescription
ProxyStrategyRoundRobinRound-robin (default); each selection advances to the next proxy, so retries naturally land on different IPs
ProxyStrategyRandomRandom; uniformly selects from healthy proxies

ConnectionConfig ​

go
type ConnectionConfig struct {
    MaxIdleConns           int           // Global max idle connections, default 50
    MaxConnsPerHost        int           // Max connections per host, default 10
    ProxyURL               string        // Proxy address, e.g. "http://proxy:8080"
    EnableSystemProxy      bool          // Auto-detect system proxy, default false
    ProxyPool              []string      // List of proxy servers for rotation
    ProxyPoolStrategy      ProxyStrategy // Proxy selection strategy, default RoundRobin
    ProxyFailureThreshold  int           // Consecutive-failure threshold, 0 defaults to 3
    ProxyCooldown          time.Duration // Circuit-break cooldown, 0 defaults to 30s
    ProxyRotatePerRequest  bool          // Force a different proxy for each independent request, default false
    ProxyRotateOnStatus    []int         // HTTP status codes that trigger proxy rotation
    EnableHTTP2            bool          // Enable HTTP/2, default true
    EnableCookies          bool          // Enable cookie management, default false
    PublicSuffixList       cookiejar.PublicSuffixList // Public-suffix database for the cookie jar, default nil
    EnableDoH              bool          // Enable DNS-over-HTTPS, default false
    DoHCacheTTL            time.Duration // DoH cache TTL, default 5min
    MaxResponseHeaderBytes int64         // Max response-header bytes, default 0 (uses Go stdlib default 1MB)
}

Field Overview ​

FieldTypeDefaultDescription
ConnectionConfig.MaxIdleConnsint50Global maximum idle connections
ConnectionConfig.MaxConnsPerHostint10Maximum connections per host (idle + active)
ConnectionConfig.ProxyURLstring""Explicit proxy address (e.g. "http://proxy:8080"); highest priority
ConnectionConfig.EnableSystemProxyboolfalseAuto-detect system proxy settings
ConnectionConfig.ProxyPool[]stringnilProxy-pool list for rotation
ConnectionConfig.ProxyPoolStrategyProxyStrategyProxyStrategyRoundRobinProxy selection strategy
ConnectionConfig.ProxyFailureThresholdint3 (0 is treated as 3)Consecutive-failure threshold before the proxy is circuit-broken
ConnectionConfig.ProxyCooldowntime.Duration30s (0 is treated as 30s)How long a circuit-broken proxy stays out of rotation
ConnectionConfig.ProxyRotatePerRequestboolfalseForce a different proxy for each independent request (requires ProxyPool)
ConnectionConfig.ProxyRotateOnStatus[]intnilHTTP status codes that trigger a proxy-switch retry (requires Retry.MaxRetries > 0)
ConnectionConfig.EnableHTTP2booltrueEnable HTTP/2
ConnectionConfig.EnableCookiesboolfalseEnable automatic cookie handling with a cookie jar
ConnectionConfig.PublicSuffixListcookiejar.PublicSuffixListnilSupplies a public-suffix database to the cookie jar (recommended: golang.org/x/net/publicsuffix.List). Without one, the jar accepts cookies on public suffixes and applies looser domain matching, which can leak cookies across unrelated subdomains
ConnectionConfig.EnableDoHboolfalseEnable DNS-over-HTTPS resolution
ConnectionConfig.DoHCacheTTLtime.Duration5minCache duration for DoH DNS responses
ConnectionConfig.MaxResponseHeaderBytesint640Maximum response-header bytes; 0 uses the Go stdlib default of 1MB (net/http.DefaultMaxHeaderBytes), defending against malicious servers sending oversized headers

PublicSuffixList is only used when EnableCookies is on (i.e. the cookie jar is active); it is the recommended way to tighten cookie domain matching and prevent supercookie leakage.

Proxy Pool ​

ProxyPool specifies a set of proxy servers; requests are distributed among them according to ProxyPoolStrategy. Connection failures (dial/TLS) trigger passive circuit breaking: after accumulating ProxyFailureThreshold failures, the proxy is temporarily removed from rotation and recovers after ProxyCooldown (half-open probing).

Priority: lower than ProxyURL, higher than EnableSystemProxy. If both ProxyURL and ProxyPool are set, ProxyURL takes effect (single-proxy mode).

ProxyRotateOnStatus specifies HTTP status codes that trigger a proxy switch on retry (e.g. []int{403} for CF/WAF IP-based blocking). Unlike connection failures, status-code rotation does not circuit-break the proxy — blocking is often target-specific (a proxy blocked on one site may work fine on another). Requires Retry.MaxRetries > 0 to take effect.

ProxyRotatePerRequest ensures that each independent request (e.g. each Get/Post call) uses a different proxy. When disabled, HTTP connection reuse causes consecutive requests to the same host to reuse the previous request's proxy tunnel, bypassing proxy-pool selection. When enabled, idle connections are closed at the start of each request, forcing the Transport to re-evaluate the proxy pool — this adds a small overhead (no connection reuse) but guarantees per-request rotation. Requires ProxyPool to take effect; has no effect with ProxyURL or when no proxy pool is configured.

ProxyRotatePerRequest vs ProxyRotateOnStatus

Both are used for proxy rotation, but their trigger mechanisms differ: ProxyRotateOnStatus triggers rotation on retry when a specific status code is received (passive, requires retries), while ProxyRotatePerRequest actively switches the proxy at the start of each request (no retries needed). For scraping/data-collection scenarios targeting the same host, ProxyRotatePerRequest ensures each request has a different source IP.

go
cfg := httpc.DefaultConfig()
cfg.Connection.ProxyPool = []string{
    "http://proxy1:8080",
    "http://proxy2:8080",
    "http://proxy3:8080",
}
cfg.Connection.ProxyPoolStrategy = httpc.ProxyStrategyRoundRobin
cfg.Connection.ProxyFailureThreshold = 3
cfg.Connection.ProxyCooldown = 30 * time.Second
cfg.Connection.ProxyRotateOnStatus = []int{403}

DNS-over-HTTPS ​

Enable DoH to reduce DNS resolution latency and prevent DNS hijacking:

go
cfg := httpc.DefaultConfig()
cfg.Connection.EnableDoH = true
cfg.Connection.DoHCacheTTL = 5 * time.Minute

Default DoH providers (by priority): Cloudflare → Google → AliDNS. See Connection Pool for details.

SecurityConfig ​

go
type SecurityConfig struct {
    TLSConfig               *tls.Config           // Custom TLS configuration
    MinTLSVersion           uint16                // Minimum TLS version, default TLS 1.2
    MaxTLSVersion           uint16                // Maximum TLS version, default TLS 1.3
    InsecureSkipVerify      bool                  // Skip certificate verification (testing only)
    MaxResponseBodySize     int64                 // Response body size limit, default 10MB
    MaxRequestBodySize      int64                 // Request body size limit, default 0 (no limit on request body size; unlike MaxResponseBodySize, no automatic fallback)
    MaxDecompressedBodySize int64                 // Decompressed body size limit, default 100MB
    AllowPrivateIPs         bool                  // Allow private IPs, default false
    SSRFExemptCIDRs         []string              // SSRF-exempt CIDRs
    ValidateURL             bool                  // URL validation, default true
    ValidateHeaders         bool                  // Header validation, default true
    StrictContentLength     bool                  // Strict Content-Length, default true
    CookieSecurity          *CookieSecurityConfig // Cookie security validation
    CertificatePinner       CertificatePinner     // Certificate pinning (SPKI hash/public key), default nil (disabled)
    RedirectWhitelist       []string              // Redirect-whitelist domains
}

Relationship Among the Three Size Limits ​

FieldDefaultDescription
MaxResponseBodySize10MBLimits the raw response-body byte count (as transferred, i.e. still compressed)
MaxDecompressedBodySize100MBLimits the decompressed response-body byte count (guards against decompression bombs); falls back to MaxResponseBodySize when unset (≤0)
MaxRequestBodySize0 (no limit)Upload request-body cap; unlike the response side there is no automatic fallback — it must be set explicitly to take effect

Certificate Pinning (CertificatePinner) ​

CertificatePinner enables certificate pinning: the TLS handshake is rejected when the server does not present a pinned key/certificate, defending against man-in-the-middle attacks even if a trusted CA is compromised. Defaults to nil (disabled). Create one with the following constructors:

ConstructorDescription
NewSPKIHashPinner(hashes ...string) (CertificatePinner, error)Create from one or more base64-encoded SPKI SHA-256 hashes (most common; supports key rotation)
NewPublicKeyPinner(publicKeys ...[]byte) (CertificatePinner, error)Create from DER-encoded PKIX public keys (SHA-256 computed internally)
NewCertificatePinnerChain(pinners ...CertificatePinner) CertificatePinnerCombine multiple pinners; accepts if any passes
go
pinner, err := httpc.NewSPKIHashPinner(
    "YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2fuihg=", // current key
    "C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=", // backup key (rotation)
)
if err != nil {
    log.Fatal(err)
}

cfg := httpc.DefaultConfig()
cfg.Security.CertificatePinner = pinner
client, err := httpc.New(cfg)

Maintenance cost

Certificate pinning requires the pinned values to be updated in sync when the server rotates its certificate (e.g. Let's Encrypt renewal). Pin multiple hashes (current + backup) and establish an update workflow to avoid connection outages caused by key rotation.

SSRF protection

AllowPrivateIPs defaults to false, blocking connections to private/reserved IPs (127.0.0.1, 10.x, 192.168.x, 169.254.x, etc. — covering localhost, loopback, link-local, and private/reserved ranges). Setting it to true completely bypasses connection-level SSRF dial validation (not just permitting private IP ranges); use it only when connecting to internal services (VPN, proxies, corporate intranets). For selective exemptions use SSRFExemptCIDRs instead. See SSRF Protection for details.

SSRF Exemption Example ​

go
cfg := httpc.DefaultConfig()
cfg.Security.SSRFExemptCIDRs = []string{
    "10.0.0.0/8",       // VPC internal
    "100.64.0.0/10",    // Tailscale
}

Invalid CIDRs make New() return an error immediately (invalid configuration: ...); they are not silently ignored.

Redirect Whitelist ​

RedirectWhitelist restricts redirects to the listed domains only; the default is nil (all redirect targets allowed). This is the gate against "redirect-based SSRF" — a more conservative alternative is Defaults.FollowRedirects = false (which is what SecureConfig() uses).

go
cfg := httpc.DefaultConfig()
cfg.Security.RedirectWhitelist = []string{
    "api.example.com",
    "cdn.example.com",
}

See Redirects for the complete picture of redirect behavior.

RetryConfig ​

go
type RetryConfig struct {
    MaxRetries         int           // Max retry count, default 3
    Delay              time.Duration // Initial retry delay, default 1s
    BackoffFactor      float64       // Backoff multiplier, default 2.0
    EnableJitter       bool          // Enable jitter, default true
    MaxRetryDelay      time.Duration // Max retry-delay cap, default 30s
    RetryNonIdempotent bool          // Allow retrying non-idempotent methods (POST, PATCH, custom), default false
    CustomPolicy       RetryPolicy   // Custom retry policy, default nil
}
FieldDefaultRange
RetryConfig.MaxRetries30-10
RetryConfig.Delay1s0-30min
RetryConfig.BackoffFactor2.01.0-10.0
RetryConfig.MaxRetryDelay30s0-30min
RetryConfig.EnableJittertrue—
RetryConfig.RetryNonIdempotentfalse—
RetryConfig.CustomPolicynilimplement RetryPolicy

Retry-delay formula: min(Delay * BackoffFactor^attempt + jitter, MaxRetryDelay)

CustomPolicy implements the RetryPolicy interface and replaces the built-in retry decisions wholesale; the default is nil (built-in policy). Like the built-in policy, CustomPolicy is only consulted for idempotent methods — to let it govern POST/PATCH retries you must also set RetryNonIdempotent (or use WithRetryNonIdempotent per request). When proxy status-code rotation is configured, the effective retry count is raised automatically — see Config Derivation and Internal Conversion.

RetryNonIdempotent defaults to false: non-idempotent requests execute exactly once — a timeout or retryable 5xx may arrive after the server has already committed the operation, and replaying the body would duplicate it (duplicate payment, double insert, ...). Enable it only when the endpoint is known to tolerate replay, or guard it with an idempotency key. Idempotent methods (GET/HEAD/PUT/DELETE/OPTIONS/TRACE) are unaffected by this switch and are always retried subject to MaxRetries.

MiddlewareConfig ​

go
type MiddlewareConfig struct {
    Middlewares []MiddlewareFunc // Middleware list, default nil
}

Contains only the Middlewares field. Request defaults (User-Agent, default headers, redirect policy) have been moved to RequestDefaults.

RequestDefaults ​

go
type RequestDefaults struct {
    UserAgent       string            // User-Agent, default "httpc/1.0"
    Headers         map[string]string // Default request headers, default empty
    FollowRedirects bool              // Follow redirects, default true
    MaxRedirects    int               // Max redirect count, default 10
}

The canonical location for per-request defaults: User-Agent, default headers, and redirect policy. Obtain sensible defaults via DefaultConfig() and modify as needed.

FieldTypeDefaultDescription
RequestDefaults.UserAgentstring"httpc/1.0"User-Agent header
RequestDefaults.Headersmap[string]stringemptyDefault headers added to every request
RequestDefaults.FollowRedirectsbooltrueWhether to follow redirects automatically
RequestDefaults.MaxRedirectsint10Cap on automatic redirects
go
cfg := httpc.DefaultConfig()
cfg.Defaults.UserAgent = "myapp/2.0"
cfg.Defaults.Headers = map[string]string{"Accept": "application/json"}
cfg.Defaults.MaxRedirects = 5

Configuration Presets ​

DefaultConfig ​

go
func DefaultConfig() Config

Secure default configuration. SSRF protection enabled by default.

SecureConfig ​

go
func SecureConfig() Config

Security-first configuration. Shorter timeouts, auto-redirect disabled, strict SSRF protection.

SettingValue
Request timeout15s
Dial timeout5s
TLSHandshake timeout5s
ResponseHeader timeout10s (Slowloris defense)
IdleConn timeout30s
MaxIdleConns20
MaxConnsPerHost5
MaxResponseBodySize5MB
MaxRetries1
Delay2s
EnableJittertrue
FollowRedirectsfalse

PerformanceConfig ​

go
func PerformanceConfig() Config

High-throughput configuration. Larger connection pool, longer timeouts, security validation preserved.

TIP

PerformanceConfig keeps ValidateURL and ValidateHeaders enabled for security. For maximum performance in trusted environments, you can manually disable them: cfg.Security.ValidateURL = false, but be aware of the security risks (injection attacks, SSRF).

SettingValue
Request timeout60s
Dial timeout15s
TLSHandshake timeout15s
ResponseHeader timeout0 (disabled, uses Request timeout)
IdleConn timeout120s
MaxIdleConns100
MaxConnsPerHost20
EnableCookiestrue
MaxResponseBodySize50MB
StrictContentLengthfalse
ValidateURLtrue
ValidateHeaderstrue
Delay500ms
BackoffFactor1.5
EnableJittertrue

TestingConfig ​

go
func TestingConfig() Config

Testing-environment configuration. Security checks disabled, short timeouts.

SettingValue
Dial timeout5s
TLSHandshake timeout5s
ResponseHeader timeout0 (disabled, uses Request timeout)
IdleConn timeout30s
MaxIdleConns10
MaxConnsPerHost5
EnableHTTP2false
EnableCookiestrue
InsecureSkipVerifytrue
AllowPrivateIPstrue
ValidateURLfalse
ValidateHeadersfalse
MaxRetries1
Delay100ms
EnableJitterfalse
UserAgenthttpc-test/1.0

DANGER

This configuration disables TLS verification and SSRF protection. For testing only. Using it outside test environments will print a security warning (see Security Warning Output).

MinimalConfig ​

go
func MinimalConfig() Config

Lightweight configuration. Retries and redirects disabled, minimal connection pool.

SettingValue
Dial timeout5s
TLSHandshake timeout5s
ResponseHeader timeout0 (disabled, uses Request timeout)
IdleConn timeout30s
MaxIdleConns10
MaxConnsPerHost2
MaxResponseBodySize1MB
MaxRetries0
Delay0
BackoffFactor1.0
EnableJitterfalse
FollowRedirectsfalse

Config Derivation and Internal Conversion ​

When New() converts the public Config into the engine configuration, some zero-value fields fall back to built-in defaults, and a few derivation rules change the actual behavior:

Derived itemRule
MaxIdleConnsPerHostComputed as MaxConnsPerHost / 2, clamped to [2, 10] and never above MaxConnsPerHost; when MaxConnsPerHost = 0 (unlimited connections) it takes 10
TLS version fallbackMinTLSVersion / MaxTLSVersion fall back to TLS 1.2 / TLS 1.3 respectively when 0
MaxRetryDelay fallbackRetry.MaxRetryDelay is treated as 30s when 0
TCP KeepAliveFixed at 30s, applied automatically with the connection-pool configuration; no need to set it
Proxy-rotation auto-raised retriesWhen ProxyRotateOnStatus or ProxyRotatePerRequest is set and the proxy pool has more than 1 entry, the effective MaxRetries is raised automatically to len(ProxyPool)-1 (capped at 10, never lowered)
ProxyRotateOnStatusPassed to the engine as "extra retryable status codes"; a hit consumes one retry budget to switch proxy

Why retries are auto-raised

With the default MaxRetries = 3, a pool of 5 proxies can only try up to the 4th proxy after a 403 before giving up. Since you configured status-code rotation, the intent is to walk the entire proxy pool, so the retry budget is raised to "pool size − 1"; if you explicitly set a larger MaxRetries, your value is kept unchanged.

Security Warning Output ​

SetSecurityWarnOutput ​

go
func SetSecurityWarnOutput(w io.Writer)

Redirects where security warnings are printed. When you use TestingConfig() or set SecurityConfig.InsecureSkipVerify (Config.Security) to true, httpc prints a [SECURITY WARNING]-level alert to this writer (each type of warning is printed at most once per process). The default output is os.Stderr; pass io.Discard to fully suppress warnings — handy for silencing them in tests or known-safe internal scenarios.

go
// Suppress security warnings in tests
httpc.SetSecurityWarnOutput(io.Discard)
cfg := httpc.TestingConfig()

Scope of effect

This setting is process-level global state that affects all subsequently created clients. The TestingConfig and InsecureSkipVerify warnings are counted independently (neither affects the other's triggering), but they share the same output writer.

Validation ​

ValidateConfig ​

go
func ValidateConfig(cfg *Config) error

Validates configuration. Called automatically inside New(), but can also be called explicitly.

The equivalent method form Config.Validate (signature func (c *Config) Validate() error, delegating directly to ValidateConfig) is handier when you already hold a Config instance — calling Validate on it is the recommended form for new code:

go
cfg := httpc.DefaultConfig()
if err := cfg.Validate(); err != nil {
    log.Fatal(err)
}
go
cfg := httpc.DefaultConfig()
cfg.Retry.MaxRetries = 100 // Out of range

if err := httpc.ValidateConfig(&cfg); err != nil {
    log.Fatal(err) // invalid retry configuration: Retry.MaxRetries must be 0-10, got 100
}

Validation rules at a glance (passing nil returns ErrNilConfig):

FieldConstraint
Timeouts.* (all 5)0 – 30min
Connection.MaxIdleConns0 – 1000
Connection.MaxConnsPerHost0 – 1000
Connection.ProxyURL and each ProxyPool entryMust be a valid proxy URL
Connection.ProxyFailureThreshold≥ 0
Connection.ProxyCooldown0 – 30min
Connection.ProxyRotateOnStatusEach status code within 100 – 599
Connection.DoHCacheTTL≥ 0
Connection.MaxResponseHeaderBytes≥ 0
Security.MaxResponseBodySize0 – 1GB
Security.MaxDecompressedBodySize0 – 100MB
Security.MaxRequestBodySize0 – 1GB
Security.MinTLSVersion / MaxTLSVersionWhen both non-zero, Min ≤ Max
Security.SSRFExemptCIDRsEach entry must be a valid CIDR
Retry.MaxRetries0 – 10
Retry.Delay0 – 30min
Retry.BackoffFactor1.0 – 10.0
Retry.MaxRetryDelay0 – 30min
Defaults.MaxRedirects0 – 50
Defaults.UserAgent≤ 512 characters, no control characters
Defaults.HeadersEvery key/value pair passes header-validity validation

Config.String ​

go
func (c *Config) String() string

Returns a safe string representation. ProxyURL credentials are masked, TLSConfig renders as <configured> or <default>, and Headers are not output.

go
cfg := httpc.DefaultConfig()
fmt.Println(cfg.String())
// Config{Timeouts:{Request: 3m0s, ...}, Security:{TLSConfig: <default>, ...}}

CookieSecurityConfig ​

go
type CookieSecurityConfig struct {
    RequireSecure                bool
    RequireHttpOnly              bool
    RequireSameSite              string
    AllowSameSiteNone            bool
    RequireSecureForSameSiteNone bool
}

Cookie security-attribute validation configuration.

FieldTypeDescription
CookieSecurityConfig.RequireSecureboolRequire cookies to carry the Secure attribute
CookieSecurityConfig.RequireHttpOnlyboolRequire cookies to carry the HttpOnly attribute
CookieSecurityConfig.RequireSameSitestringRequired SameSite value, e.g. "Strict", "Lax"; empty string means no check
CookieSecurityConfig.AllowSameSiteNoneboolWhether SameSite=None is allowed; when false and RequireSameSite is empty, cookies with SameSite=None are rejected
CookieSecurityConfig.RequireSecureForSameSiteNoneboolForce the Secure attribute when SameSite=None (true in DefaultCookieSecurityConfig(); false when constructing a zero-value struct directly — always prefer the factory constructors)

DefaultCookieSecurityConfig ​

go
func DefaultCookieSecurityConfig() *CookieSecurityConfig

Default cookie security configuration. Does not require Secure/HttpOnly/SameSite attributes, but enforces that cookies with SameSite=None must set Secure.

StrictCookieSecurityConfig ​

go
func StrictCookieSecurityConfig() *CookieSecurityConfig

Strict cookie security configuration. Requires Secure, HttpOnly, and SameSite=Strict.

go
cfg := httpc.DefaultConfig()
cfg.Security.CookieSecurity = httpc.StrictCookieSecurityConfig()

Field-by-field comparison of the two factories:

FieldDefaultCookieSecurityConfigStrictCookieSecurityConfig
RequireSecurefalsetrue
RequireHttpOnlyfalsetrue
RequireSameSite"" (not required)"Strict"
AllowSameSiteNonetruefalse
RequireSecureForSameSiteNonetruetrue