Documentation ¶
Overview ¶
Package download provides a library to handle file download requests.
Index ¶
- Variables
- func ContextWithEtag(ctx context.Context, etag string) context.Context
- func EtagFromContext(ctx context.Context) string
- func GetOrHeadFile(w http.ResponseWriter, r *http.Request, fs storage.FS, spaceID string)
- func RangesMIMESize(ranges []HTTPRange, contentType string, contentSize int64) (encSize int64)
- func SumRangesSize(ranges []HTTPRange) (size int64)
- type HTTPRange
Constants ¶
This section is empty.
Variables ¶
var ErrNoOverlap = errors.New("invalid range: failed to overlap")
ErrNoOverlap is returned by serveContent's parseRange if first-byte-pos of all of the byte-range-spec values is greater than the content size.
var ErrSeeker = errors.New("seeker can't seek")
ErrSeeker is returned by ServeContent's sizeFunc when the content doesn't seek properly. The underlying Seeker's error text isn't included in the sizeFunc reply so it's not sent over HTTP to end users.
Functions ¶
func ContextWithEtag ¶ added in v2.16.0
ContextWithEtag returns a new `context.Context` that holds an etag.
func EtagFromContext ¶ added in v2.16.0
EtagFromContext returns the etag previously associated with `ctx`, or `""` if no such etag could be found.
func GetOrHeadFile ¶
GetOrHeadFile returns the requested file content
func RangesMIMESize ¶
RangesMIMESize returns the number of bytes it takes to encode the provided ranges as a multipart response.
func SumRangesSize ¶
SumRangesSize adds up the length of all ranges
Types ¶
type HTTPRange ¶
type HTTPRange struct {
Start, Length int64
}
HTTPRange specifies the byte range to be sent to the client.
func ParseRange ¶
ParseRange parses a Range header string as per RFC 7233. errNoOverlap is returned if none of the ranges overlap.
func (HTTPRange) ContentRange ¶
ContentRange formats a Range header string as per RFC 7233.
func (HTTPRange) MimeHeader ¶
func (r HTTPRange) MimeHeader(contentType string, size int64) textproto.MIMEHeader
MimeHeader creates range relevant MimeHeaders