contentcoding

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contentcoding removes one HTTP content-coding (RFC 9110 §8.4.1) layer from a body: gzip (and its x-gzip alias), deflate, br and zstd. The coding names are the IANA HTTP Content Coding registry's, matched exactly after case folding — a protocol vocabulary, not a guess about the bytes.

The response normaliser (pkg/deparos/responsechain) decodes wire bodies through NewReader, and the store (pkg/database) decodes ingested bodies through Decode, so a body reads the same whichever path it took.

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLarge = errors.New("decoded body exceeds the size cap")

ErrTooLarge is returned by Decode when the decoded body exceeds its cap.

Functions

func Decode

func Decode(coding string, body []byte, maxDecoded int64) ([]byte, error)

Decode removes one coding layer from body, reading at most maxDecoded bytes of output (0 = no cap). It fails on an unsupported coding, on bytes that do not decode, on a stream that does not reach its end, and with ErrTooLarge past the cap — a caller storing the result keeps the original on any error rather than a fragment. "deflate" also accepts a raw (headerless) DEFLATE stream, which servers commonly send under that name.

func NewReader

func NewReader(coding string, r io.Reader) (io.ReadCloser, error)

NewReader wraps r in a decoder for coding. An empty, "identity" or unknown coding returns r unchanged (wrapped to a ReadCloser), so a caller can pass any header value through. deflate is the zlib-wrapped form RFC 9110 names.

func Normalize

func Normalize(coding string) string

Normalize folds a Content-Encoding value for matching: trimmed, lower case. A value listing several codings ("gzip, br") is returned whole.

func Supported

func Supported(coding string) bool

Supported reports whether coding (one name, any case) is a coding this package decodes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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