qlist

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package qlist provides a processor for HTTP Quality Lists

Index

Constants

View Source
const (
	MinimumQuality = 0.    // MinimumQuality is 0
	MaximumQuality = 1.    // MaximumQuality is 1
	Epsilon        = 0.001 // Epsilon is the accuracy of the quality, 1/100
)
View Source
const (
	// Accept is the canonical header name used for negotiating a MIME Type
	// for the content of the Request response
	Accept = "Accept"
)
View Source
const (
	// AcceptEncoding is the canonical name given to the header used
	// to indicate compression options
	AcceptEncoding = "Accept-Encoding"
)

Variables

This section is empty.

Functions

func BestEncoding

func BestEncoding(supported []string, hdr http.Header) (string, bool)

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

func MediaRangeBestQuality(supported []string, header string) string

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

func MediaRangeQuality(mimetype string, ranges ...string) (quality float32)

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 representings on 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) 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) Quality

func (q QualityValue) Quality() float32

Quality of the Value entry

func (QualityValue) String

func (q QualityValue) String() string

func (QualityValue) Value

func (q QualityValue) Value() string

Value tells the entry the quality refers to

Jump to

Keyboard shortcuts

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