Documentation
¶
Overview ¶
Package httpreader implements io.ReaderAt over an http.Client for a resource that implements HTTP Range requests (RFC7233). Various tricks are implemented to maximize compatibility.
Tricks ¶
- Only use GET requests, to allow for locked-down signed requests.
- Request last byte to negate weird CDN caching.
- Try multiple ways to get the resource size.
Handled weirdness ¶
- Server not handling negative ranges correctly.
- Server not reporting content length when making Range requests.
- "200 OK" for a range starting at 0.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentRange ¶
type ContentRange struct {
First, Last, Length int64
}
ContentRange is a parsed "bytes" content range.
Unpopulated sections of the header are set to -1; refer to RFC7233 for more information.
func (*ContentRange) Parse ¶
func (r *ContentRange) Parse(data string) error
Parse populates the receiver with the "bytes" content range from the supplied header value or reports an error.
func (*ContentRange) Reset ¶
func (r *ContentRange) Reset()
Reset sets all fields to a known value (-1).
type Option ¶
Option is used to set options in New.
func WithHeaders ¶
WithHeaders sets additional headers for requests.
type RangeUnsupported ¶
RangeUnsupported is reported when Range requests are unsupported by the indicated resource.
func (*RangeUnsupported) Error ¶
func (e *RangeUnsupported) Error() string
func (*RangeUnsupported) Is ¶
func (e *RangeUnsupported) Is(tgt error) bool
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements io.ReaderAt over an HTTP resource that implements range requests.
The Reader is guaranteed to only makes GET requests.
Callers can use an io.SectionReader if they require an io.Reader interface.
func New ¶
New constructs a reader for the resource at "uri", using the supplied context.Context and http.Client.
The Context is used for the lifetime of the Reader. All ReadAt calls translate to network roundtrips. Callers should arrange for buffering and chunking for the best performance. They may also want to check the discovered size and eagerly fetch the resource if it's under some threshold. This is not handled in this package.
The returned Reader must have Reader.Close called or the program may panic.
func (*Reader) Close ¶
Close implements io.Closer.
Callers must call Close on any Reader to release resources, or the program may panic.
func (*Reader) ReadAt ¶
ReadAt implements io.ReaderAt.