encoding

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package encoding implements generic support for content negotiation.

Index

Constants

View Source
const (
	Gzip     = "gzip"
	Compress = "compress"
	Deflate  = "deflate"
	Brotli   = "br"
	Identity = "identity"
	Any      = "*"
)

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding

Variables

View Source
var (
	// ErrEmptyHeader is returned when doing content negotiation with an empty header.
	ErrEmptyHeader = errors.New("empty header")

	// ErrMalformedWeight is returned when the Weight value is malformed.
	ErrMalformedWeight = errors.New("malformed weight")
)

Functions

This section is empty.

Types

type Preference

type Preference map[string]Weight

A Preference holds a list of encodings with their Weight.

func ParseHeader

func ParseHeader(acceptHeader string) (Preference, error)

ParseHeader parse Accept-Encoding headers.

func (Preference) Negotiate

func (pref Preference) Negotiate(acceptHeader string, wildcardStrategy WildcardResolutionStrategy) ([]string, error)

Negotiate returns a slice of accepted content encodings for the request's Accept-Encoding header. The offer earlier in the list is preferred. If no offers are acceptable, then an empty slice is returned.

type Weight

type Weight float32

A Weight is the equivalent of a quality values in the HTTP spec.

It is used to assign a relative "weight" to the preference for that associated kind of content. See https://httpwg.org/specs/rfc7231.html#quality.values

type WildcardResolutionStrategy

type WildcardResolutionStrategy int

A WildcardResolutionStrategy is a strategy to resolve a wildcard character during content negotiation.

const (
	// None doesn't apply any transformation and returns '*'.
	None WildcardResolutionStrategy = iota

	// AliasIdentity replaces '*' with 'Identity'.
	AliasIdentity

	// UseServerPref uses the server Preference to resolve the wildcard.
	UseServerPref
)

Jump to

Keyboard shortcuts

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