httphdr

package
v0.0.0-...-113f59a Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

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.

Jump to

Keyboard shortcuts

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