Documentation
¶
Overview ¶
Package httputil provides a thin HTTP+JSON helper for providers.
Index ¶
- Constants
- func GetHTML(url string, headers map[string]string, timeout time.Duration) (string, error)
- func GetJSON(url string, headers map[string]string, timeout time.Duration, dst any) error
- func PostJSON(url string, headers map[string]string, payload any, timeout time.Duration, ...) error
- func Truncate(s string, n int) string
- type Error
Constants ¶
const DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
DefaultUserAgent is sent on every request unless the caller explicitly sets a User-Agent header. Go's default "Go-http-client/1.1" gets blocked by Cloudflare, so we use a real browser UA.
Variables ¶
This section is empty.
Functions ¶
func GetHTML ¶ added in v0.3.0
GetHTML performs a GET request and returns the response body as a string.
Types ¶
type Error ¶
Error is returned for non-2xx HTTP responses.
func (*Error) RetryAfter ¶ added in v0.5.0
RetryAfter returns the absolute time the server asked us to wait until before retrying, parsed from common rate-limit / server-busy response headers. Returns zero-time when no recognized hint is present or the status code isn't one that should carry one.
Recognized headers, in order of preference:
- Retry-After (RFC 7231: seconds OR HTTP date)
- x-ratelimit-reset (Unix timestamp OR seconds-from-now)
- anthropic-ratelimit-requests-reset (ISO 8601)
- anthropic-ratelimit-tokens-reset (ISO 8601)