httputil

package
v0.1.151 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 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/v3; 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 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 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 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 and runs httpx's rate-limit-only retry mode (v3's Do + WithRateLimitOnly, which absorbed the v2 RetryOnRateLimit helper): only rate limits are retried — waiting min(hint, maxWait) — and every other error, transient included, returns immediately (transient retry is the caller's outer wrapper's job).

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