httprange

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package httprange parses and validates exact HTTP byte ranges.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid       = errors.New("invalid byte range")
	ErrUnsatisfiable = errors.New("unsatisfiable byte range")
)

Functions

func UnsatisfiedContentRange

func UnsatisfiedContentRange(size int64) string

UnsatisfiedContentRange returns the Content-Range value for a 416 response.

func ValidateResponse

func ValidateResponse(requested Range, value string, contentLength int64) (int64, error)

ValidateResponse verifies that a partial response exactly matches the requested range and body length.

Types

type ContentRange

type ContentRange struct {
	Range Range
	Size  int64
}

ContentRange is a satisfied HTTP Content-Range value.

func ParseContentRange

func ParseContentRange(value string) (ContentRange, error)

ParseContentRange parses Content-Range: bytes N-M/TOTAL.

type Range

type Range struct {
	Start int64
	End   int64
}

Range is an exact inclusive byte range.

func New

func New(start, end int64) (Range, error)

New constructs a validated exact range.

func ParseExact

func ParseExact(value string) (Range, error)

ParseExact parses a single bytes=N-M range. Open-ended, suffix, and multipart ranges are deliberately rejected.

func (Range) HeaderValue

func (r Range) HeaderValue() string

HeaderValue returns the HTTP Range header value.

func (Range) Length

func (r Range) Length() int64

Length returns the number of bytes in the range.

func (Range) ValidateSize

func (r Range) ValidateSize(size int64) error

ValidateSize verifies that the entire range is within an object of size.

Jump to

Keyboard shortcuts

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