Documentation
¶
Overview ¶
Package httputil provides shared HTTP utilities for subtitle providers. Behavioral logic is delegated to github.com/cplieger/httpx/v2; this package retains application-specific constants and thin adapters that bridge httpx error types to the internal api.* error types used across the codebase.
Index ¶
- Constants
- func CheckHTTPStatus(resp *http.Response) error
- func DrainClose(rc io.ReadCloser)
- func IsTransient(err error) bool
- func JitteredBackoff(backoff time.Duration) time.Duration
- func LimitedBody(resp *http.Response) io.ReadCloser
- func ParseRetryAfter(resp *http.Response) time.Duration
- func RedactSecret(err error, secret string) error
- func RedactTransportError(err error, prefix, secret string) error
- func RetryOnRateLimit(ctx context.Context, maxAttempts int, maxWait time.Duration, fn func() error) error
- func SafeDouble(d time.Duration) time.Duration
- func SleepCtx(ctx context.Context, d time.Duration) error
- type HTTPStatusError
Constants ¶
const ContentTypeJSON = "application/json"
ContentTypeJSON is the MIME type for JSON request/response bodies.
const HeaderContentType = "Content-Type"
HeaderContentType is the canonical HTTP header name for content type.
const MaxDownloadBytes = 10 << 20
MaxDownloadBytes is the maximum response body size for subtitle/archive downloads (10 MB).
const MaxErrorBodyBytes = 1 << 20
MaxErrorBodyBytes is the maximum size for reading error response bodies (1 MB).
const MaxJSONResponseBytes = 5 << 20
MaxJSONResponseBytes is the maximum size for a JSON API response body (5 MB).
const MaxListResponseBytes = 2 << 20
MaxListResponseBytes is the maximum size for a list/detail JSON response (2 MB).
const MaxSearchResponseBytes = 1 << 20
MaxSearchResponseBytes is the maximum size for a search/lookup JSON response (1 MB).
const MaxSingleSubtitleBytes = 5 << 20
MaxSingleSubtitleBytes is the maximum size for a single subtitle file download (5 MB).
const UserAgent = "Subflux/1.0"
UserAgent is the default User-Agent header sent by all providers.
Variables ¶
This section is empty.
Functions ¶
func CheckHTTPStatus ¶
CheckHTTPStatus maps HTTP error status codes to typed errors. Returns nil for 2xx/3xx. Bridges httpx error types to api.* types so callers can continue using errors.As with *api.AuthError and *api.RateLimitError.
func DrainClose ¶
func DrainClose(rc io.ReadCloser)
DrainClose reads remaining bytes from rc before closing it.
func IsTransient ¶
IsTransient returns true for errors likely caused by temporary server or network issues worth retrying. Bridges api.AuthError and api.RateLimitError exclusion with httpx.IsTransient for network checks.
func JitteredBackoff ¶
JitteredBackoff returns a jittered duration in [backoff/2, backoff].
func LimitedBody ¶
func LimitedBody(resp *http.Response) io.ReadCloser
LimitedBody wraps resp.Body with a read cap while preserving Close.
func ParseRetryAfter ¶
ParseRetryAfter parses the Retry-After header from a response. Delegates to httpx.ParseRetryAfterResponse (uncapped, matching original behavior).
func RedactSecret ¶
RedactSecret replaces occurrences of secret in err's message with "REDACTED".
func RedactTransportError ¶
RedactTransportError unwraps *url.Error and redacts the secret.
func RetryOnRateLimit ¶
func RetryOnRateLimit(ctx context.Context, maxAttempts int, maxWait time.Duration, fn func() error) error
RetryOnRateLimit retries fn up to maxAttempts times when it returns a *api.RateLimitError. Bridges the api.RateLimitError type to httpx.RateLimitError.
func SafeDouble ¶
SafeDouble doubles a duration while guarding against int64 overflow.
Types ¶
type HTTPStatusError ¶
type HTTPStatusError = httpx.HTTPStatusError
HTTPStatusError represents a non-2xx HTTP response that is not already covered by a more specific typed error. Delegates to httpx.HTTPStatusError.