httprange

package
v0.0.0-...-cf2fa2e Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package httprange provides a utility function for parsing HTTP Range headers.

The function supports requests for a single range of bytes, which is the most common use case for range requests. It returns the start and end positions of the requested range, along with the corresponding Content-Range and Content-Length strings for use in an HTTP 206 Partial Content response.

The current implementation does not fully comply with RFC 7233 in the following ways:

  1. The function assumes that the unit is always 'bytes'. According to RFC 7233, a range unit identifier can be bytes or any token registered in the HTTP Range Unit Registry. However, 'bytes' is the only range unit identifier defined by HTTP/1.1, and it's the most commonly used in practice.

  2. The function only supports a single range. RFC 7233 allows a client to request multiple ranges in a single request, but this is not often used in practice and can increase the complexity of the server's response.

These limitations are deemed acceptable for the typical use cases this function is designed for, and they significantly simplify the implementation. However, if full compliance with RFC 7233 is required, this function should not be used.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid range header format")

Functions

This section is empty.

Types

type Range

type Range struct {
	Start  int64
	Length int64
	Header string
}

func Parse

func Parse(rangeHeader string, size int64) (*Range, error)

Parse parses the Range header from an HTTP request. It supports bytes as a unit and doesn't support multiple range requests. The function returns a Range struct containing the start and end positions of the range, the Content-Range header and the Content-Length header.

Jump to

Keyboard shortcuts

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