tailscale.comtailscale.com/util/httphdr Index | Files

package httphdr

import "tailscale.com/util/httphdr"

Package httphdr implements functionality for parsing and formatting standard HTTP headers.

Index

Functions

func FormatContentRange

func FormatContentRange(start, length, completeLength int64) (hdr string, ok bool)

FormatContentRange parses a "Content-Range" header per RFC 7233, section 4.2. It only handles "Content-Range" headers where the units is "bytes". The "Content-Range" header is usually only specified in HTTP responses.

If start and length are non-positive, then it encodes just the completeLength, which must be a non-negative value.

Otherwise, it encodes the start and length as a byte-range, and optionally emits the complete length if it is non-negative. The length must be positive (as RFC 7233 uses inclusive end offsets).

func FormatRange

func FormatRange(ranges []Range) (hdr string, ok bool)

FormatRange formats a "Range" header per RFC 7233, section 3. It only handles "Range" headers where the units is "bytes". The "Range" header is usually only specified in GET requests.

func ParseContentRange

func ParseContentRange(hdr string) (start, length, completeLength int64, ok bool)

ParseContentRange parses a "Content-Range" header per RFC 7233, section 4.2. It only handles "Content-Range" headers where the units is "bytes". The "Content-Range" header is usually only specified in HTTP responses.

If only the completeLength is specified, then start and length are both zero.

Otherwise, the parses the start and length and the optional completeLength, which is -1 if unspecified. The start is non-negative and the length is positive.

Types

type Range

type Range struct {
	// Start is the starting offset.
	// It is zero if Length is negative; it must not be negative.
	Start int64
	// Length is the length of the content.
	// It is zero if the length extends to the end of the content.
	// It is negative if the length is relative to the end (e.g., last 5 bytes).
	Length int64
}

Range is a range of bytes within some content.

func ParseRange

func ParseRange(hdr string) (ranges []Range, ok bool)

ParseRange parses a "Range" header per RFC 7233, section 3. It only handles "Range" headers where the units is "bytes". The "Range" header is usually only specified in GET requests.

Source Files

httphdr.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
1 day ago

Tools for package owners.