Documentation ¶
Overview ¶
Package qlist provides a processor for HTTP Quality Lists
Index ¶
- Constants
- func BestEncoding(supported []string, hdr http.Header) (string, bool)
- func BestQuality(supported []string, ql QualityList) (string, float32, bool)
- func BestQualityParsed(supported, accepted []QualityValue) (string, float32, bool)
- func BestQualityWithIdentity(supported []string, ql QualityList, identity string) (string, float32, bool)
- func FitnessAndQuality(target string, accepted QualityList) (fitness int, quality float32)
- func FitnessAndQualityParsed(target QualityValue, accepted QualityList) (fitness int, quality float32)
- func MediaRangeBestQuality(supported []string, header string) string
- func MediaRangeFitnessAndQuality(mimetype string, accepted QualityList) (fitness int, quality float32)
- func MediaRangeQuality(mimetype string, ranges ...string) (quality float32)
- func MediaRangeQualityParsed(mimetype string, parsedRanges QualityList) (quality float32)
- type QualityList
- func ParseMediaRangeHeader(hdr http.Header) (QualityList, error)
- func ParseMediaRangeHeaders(hdrs []string) (out QualityList, err error)
- func ParseMediaRangeString(ranges string) (out QualityList, err error)
- func ParseQualityHeader(hdr http.Header, name string) (out QualityList, err error)
- func ParseQualityString(qlist string) (out QualityList, err error)
- type QualityValue
- func (q QualityValue) Get(attr string) (string, bool)
- func (q QualityValue) IsMediaType() bool
- func (q QualityValue) IsZero() bool
- func (q QualityValue) Match(t QualityValue) bool
- func (q QualityValue) MatchFitness(t QualityValue) int
- func (q QualityValue) Quality() float32
- func (q QualityValue) String() string
- func (q QualityValue) Value() string
Constants ¶
const ( MinimumQuality = 0. // MinimumQuality is 0 MaximumQuality = 1. // MaximumQuality is 1 Epsilon = 0.001 // Epsilon is the accuracy of the quality, 1/100 )
const ( // Accept is the canonical header name used for negotiating a MIME Type // for the content of the Request response Accept = consts.Accept )
const ( // AcceptEncoding is the canonical name given to the header used // to indicate compression options AcceptEncoding = consts.AcceptEncoding )
Variables ¶
This section is empty.
Functions ¶
func BestEncoding ¶
BestEncoding chooses the best supported compression option considering the Accept-Encoding header
func BestQuality ¶
func BestQuality(supported []string, ql QualityList) (string, float32, bool)
BestQuality searches for the best option among supported values based on the provided QualityList
func BestQualityParsed ¶
func BestQualityParsed(supported, accepted []QualityValue) (string, float32, bool)
BestQualityParsed takes a list of supported and accepted quality entries and finds the best match among all combinations.
func BestQualityWithIdentity ¶
func BestQualityWithIdentity(supported []string, ql QualityList, identity string) (string, float32, bool)
BestQualityWithIdentity searches for the best option among supported values based on the provided QualityList, but gives special treatment to an identity option which is used if it's the best or if nothing was chosen but the identity isn't explicitly forbidden
func FitnessAndQuality ¶
func FitnessAndQuality(target string, accepted QualityList) (fitness int, quality float32)
FitnessAndQuality finds the best accepted match for a target, returning fitness and quality. (-1, 0) if no match was found
func FitnessAndQualityParsed ¶
func FitnessAndQualityParsed(target QualityValue, accepted QualityList) (fitness int, quality float32)
FitnessAndQualityParsed finds the best accepted match for a target, returning fitness and quality. (-1, 0) if no match was found
func MediaRangeBestQuality ¶
MediaRangeBestQuality takes a list of supported mime-types and finds the best match for all the media-ranges listed in header. The value of header must be a string that conforms to the format of the HTTP Accept: header. The value of 'supported' is a list of mime-types.
func MediaRangeFitnessAndQuality ¶
func MediaRangeFitnessAndQuality(mimetype string, accepted QualityList) (fitness int, quality float32)
MediaRangeFitnessAndQuality finds the best match for a given mime-type against a list of media_ranges that have already been parsed by ParseMediaRange(). Returns a tuple of the fitness value and the value of the 'q' quality parameter of the best match, or (-1, 0) if no match was found. Just as for QualityParsed(), 'parsedranges' must be a list of parsed media ranges.
func MediaRangeQuality ¶
MediaRangeQuality returns the quality 'q' of a mime-type when compared against the media-ranges in ranges
func MediaRangeQualityParsed ¶
func MediaRangeQualityParsed(mimetype string, parsedRanges QualityList) (quality float32)
MediaRangeQualityParsed find the best match for a given mime-type against a list of media_ranges that have already been parsed by ParseMediaRange(). Returns the 'q' quality parameter of the best match, 0 if no match was found. This function bahaves the same as quality() except that 'parsed_ranges' must be a list of parsed media ranges.
Types ¶
type QualityList ¶
type QualityList []QualityValue
QualityList is a list of QualityValue
func ParseMediaRangeHeader ¶
func ParseMediaRangeHeader(hdr http.Header) (QualityList, error)
ParseMediaRangeHeader extract a accepted media ranges from the Accept header
func ParseMediaRangeHeaders ¶
func ParseMediaRangeHeaders(hdrs []string) (out QualityList, err error)
ParseMediaRangeHeaders extracts a QualityList from a list of Accept headers
func ParseMediaRangeString ¶
func ParseMediaRangeString(ranges string) (out QualityList, err error)
ParseMediaRangeString extracts a QualityList from a string representing an Accept header
func ParseQualityHeader ¶
func ParseQualityHeader(hdr http.Header, name string) (out QualityList, err error)
ParseQualityHeader extracts a QualityList from the headers of a request
func ParseQualityString ¶
func ParseQualityString(qlist string) (out QualityList, err error)
ParseQualityString extracts a QualityList from a string representing one Header's content
func (QualityList) String ¶
func (ql QualityList) String() string
type QualityValue ¶
type QualityValue struct {
// contains filtered or unexported fields
}
QualityValue is a parsed item of a QualityList
func AsMediaRange ¶
func AsMediaRange(q QualityValue) (QualityValue, bool)
AsMediaRange converts a QualityValue into a valid MediaRange
func ParseMediaRange ¶
func ParseMediaRange(mimerange string) (QualityValue, error)
ParseMediaRange parses a Media-Range
func ParseQualityValue ¶
func ParseQualityValue(s string) (QualityValue, error)
ParseQualityValue parses one QualityValue
func (QualityValue) Get ¶
func (q QualityValue) Get(attr string) (string, bool)
Get retrieves the value of an attribute
func (QualityValue) IsMediaType ¶ added in v0.5.3
func (q QualityValue) IsMediaType() bool
IsMediaType checks if the QualityValue represents only specific Media Type and not a Media Range.
func (QualityValue) IsZero ¶
func (q QualityValue) IsZero() bool
IsZero tells if the QualityValue doesn't hold any information
func (QualityValue) Match ¶
func (q QualityValue) Match(t QualityValue) bool
Match answers the question if we match a target. For an entry to match another it needs to have the same number of parts, and each pair of parts be identical or at least one of them a "*" wildcard
func (QualityValue) MatchFitness ¶
func (q QualityValue) MatchFitness(t QualityValue) int
MatchFitness answers the question of how well we match a target. simple match gives one point, as do matching target attributes. exact matches at the lowest part gives 10, and that grows geometrically as parts we move up in the chain
func (QualityValue) String ¶
func (q QualityValue) String() string
func (QualityValue) Value ¶
func (q QualityValue) Value() string
Value tells the entry the quality refers to