httputil

package
v0.1.147 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 7 Imported by: 0

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

View Source
const ContentTypeJSON = "application/json"

ContentTypeJSON is the MIME type for JSON request/response bodies.

View Source
const HeaderContentType = "Content-Type"

HeaderContentType is the canonical HTTP header name for content type.

View Source
const MaxDownloadBytes = 10 << 20

MaxDownloadBytes is the maximum response body size for subtitle/archive downloads (10 MB).

View Source
const MaxErrorBodyBytes = 1 << 20

MaxErrorBodyBytes is the maximum size for reading error response bodies (1 MB).

View Source
const MaxJSONResponseBytes = 5 << 20

MaxJSONResponseBytes is the maximum size for a JSON API response body (5 MB).

View Source
const MaxListResponseBytes = 2 << 20

MaxListResponseBytes is the maximum size for a list/detail JSON response (2 MB).

View Source
const MaxSearchResponseBytes = 1 << 20

MaxSearchResponseBytes is the maximum size for a search/lookup JSON response (1 MB).

View Source
const MaxSingleSubtitleBytes = 5 << 20

MaxSingleSubtitleBytes is the maximum size for a single subtitle file download (5 MB).

View Source
const UserAgent = "Subflux/1.0"

UserAgent is the default User-Agent header sent by all providers.

Variables

This section is empty.

Functions

func CheckHTTPStatus

func CheckHTTPStatus(resp *http.Response) error

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

func IsTransient(err error) bool

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

func JitteredBackoff(backoff time.Duration) time.Duration

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

func ParseRetryAfter(resp *http.Response) time.Duration

ParseRetryAfter parses the Retry-After header from a response. Delegates to httpx.ParseRetryAfterResponse (uncapped, matching original behavior).

func RedactSecret

func RedactSecret(err error, secret string) error

RedactSecret replaces occurrences of secret in err's message with "REDACTED".

func RedactTransportError

func RedactTransportError(err error, prefix, secret string) error

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

func SafeDouble(d time.Duration) time.Duration

SafeDouble doubles a duration while guarding against int64 overflow.

func SleepCtx

func SleepCtx(ctx context.Context, d time.Duration) error

SleepCtx sleeps for the given duration or returns early if the context is cancelled.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL