Documentation
¶
Overview ¶
Package httpclient provides a shared, rate-limited, concurrent HTTP client used across all SwaggerVu modules.
Index ¶
- Variables
- func ForEach[T any](ctx context.Context, concurrency int, items []T, ...)
- func IsSensitiveHeader(name string) bool
- func NormalizeAllowedHosts(hosts []string) ([]string, error)
- func NormalizeCredentialOrigins(origins []string) ([]string, error)
- type Client
- func (c *Client) Do(ctx context.Context, method, url string, body io.Reader) (*Response, error)
- func (c *Client) DoWithHeaders(ctx context.Context, method, url string, body io.Reader, ...) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string) (*Response, error)
- func (c *Client) ValidateURL(ctx context.Context, raw string) error
- type Options
- type Response
Constants ¶
This section is empty.
Variables ¶
var ErrRequestBudget = errors.New("request budget exhausted")
Functions ¶
func ForEach ¶
func ForEach[T any](ctx context.Context, concurrency int, items []T, fn func(ctx context.Context, item T))
ForEach runs fn over items using up to `concurrency` workers. It stops early if ctx is cancelled.
func IsSensitiveHeader ¶
IsSensitiveHeader reports whether a header must be bound to an exact origin.
func NormalizeAllowedHosts ¶
NormalizeAllowedHosts validates exact hostnames/IP literals used as authority boundaries. URLs, ports, wildcards, userinfo, and path/query syntax are refused.
func NormalizeCredentialOrigins ¶
NormalizeCredentialOrigins validates and canonicalizes scheme+host+port boundaries. Paths, queries, fragments, and userinfo are refused.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin wrapper around http.Client adding a global rate limiter.
func (*Client) DoWithHeaders ¶
func (c *Client) DoWithHeaders(ctx context.Context, method, url string, body io.Reader, headers map[string]string) (*Response, error)
DoWithHeaders performs a request, applying per-request headers on top of the client defaults (used to send the generated Content-Type and header params).
func (*Client) ValidateURL ¶
ValidateURL applies scheme, scope, DNS, and private/special-address policy without sending a request. It is used before handing an initial URL to a component such as a browser that does not use Client's transport.
type Options ¶
type Options struct {
Timeout time.Duration
Insecure bool
Proxy string // http(s):// proxy URL
UserAgent string
RandomizeUA bool
RatePerSecond float64 // 0 = unlimited
Headers map[string]string
FollowRedirect bool
AllowedHosts []string
AllowPrivate bool
MaxRequests int64 // 0 = unlimited
MaxBodyBytes int64
CredentialOrigins []string
}
Options configures a Client.