Documentation ¶
Overview ¶
Package encoding implements generic support for content negotiation.
Index ¶
Constants ¶
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 ¶
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 ¶
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 )