Documentation
¶
Overview ¶
Package resumable provides an http.RoundTripper that transparently resumes interrupted GET responses from servers that support byte ranges.
───────────────────────────── How it works ─────────────────────────────
- For GET responses with status 200 or 206 and "Accept-Ranges: bytes", the transport replaces resp.Body with a resumable reader.
- If a mid-stream read fails (e.g., connection cut), it issues a follow-up request with a "Range" header to continue from the last delivered byte. It uses ETag (strong only) or Last-Modified via If-Range for safety.
- If the server doesn’t support ranges (or for non-GET), it passes through the response unmodified.
───────────────────────────── Notes & caveats ───────────────────────────
- Only single byte ranges are supported when the original request already includes Range (multi-range requests are passed through without resuming).
- Auto-decompression must not be active, or offsets won’t line up. If the initial response was transparently decompressed (resp.Uncompressed == true) or Content-Encoding was set, resumption is disabled for that response.
- Cookies added by an http.Client Jar after the initial response aren’t automatically applied to follow-up range requests (since they bypass http.Client). Existing request headers (incl. Cookie, Authorization, etc.) are preserved, but Set-Cookie from the initial response won't be consulted.
- Some servers don’t advertise Accept-Ranges but still support Range. This implementation requires explicit "Accept-Ranges: bytes" for safety.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffFunc ¶
BackoffFunc computes the sleep duration for a given retry attempt (0-based).
type Option ¶
type Option func(*ResumableTransport)
Option configures a ResumableTransport.
func WithBackoff ¶
func WithBackoff(f BackoffFunc) Option
WithBackoff sets the backoff strategy for resume attempts. Default: jittered exponential starting at 200ms, capped at 5s.
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of resume attempts after an error. Default: 3.
type ResumableTransport ¶
type ResumableTransport struct {
// contains filtered or unexported fields
}
ResumableTransport wraps another http.RoundTripper and transparently retries mid-stream failures for GET requests against servers that support range requests.
func New ¶
func New(base http.RoundTripper, opts ...Option) *ResumableTransport
New returns a ResumableTransport wrapping base. If base is nil, http.DefaultTransport is used. Options configure retries/backoff.