Documentation ¶
Overview ¶
Package header provides implementations that define HTTP header behavior necessary to facilitate content negotiation.
Index ¶
- Constants
- Variables
- type Accept
- type AcceptCharset
- type AcceptEncoding
- type AcceptFeatures
- type AcceptLanguage
- type Alternates
- type CharsetRange
- type ContentCodingRange
- func (cc ContentCodingRange) CodingRange() string
- func (cc ContentCodingRange) Compatible(coding string) bool
- func (cc ContentCodingRange) IsCoding() bool
- func (cc ContentCodingRange) IsIdentity() bool
- func (cc ContentCodingRange) IsWildcard() bool
- func (cc ContentCodingRange) QualityValue() QualityValue
- func (cc ContentCodingRange) String() string
- type FalseDegradation
- type FeatureExpression
- func (e FeatureExpression) HasValue() bool
- func (e FeatureExpression) IsExclusive() bool
- func (e FeatureExpression) IsWildcard() bool
- func (e FeatureExpression) String() string
- func (e FeatureExpression) Tag() FeatureTag
- func (e FeatureExpression) Type() FeatureExpressionType
- func (e FeatureExpression) Value() FeatureTagValue
- type FeatureExpressionType
- type FeatureList
- type FeatureListElement
- type FeaturePredicate
- type FeaturePredicateBag
- type FeatureSet
- type FeatureTag
- type FeatureTagValue
- type LanguageRange
- type MediaRange
- func (mr MediaRange) Compatible(mediaType string) (bool, error)
- func (mr MediaRange) HasParams() (b bool)
- func (mr MediaRange) IsSubTypeWildcard() bool
- func (mr MediaRange) IsTypeWildcard() bool
- func (mr MediaRange) Param(p string) (string, bool)
- func (mr MediaRange) Precedence() int
- func (mr MediaRange) QualityValue() QualityValue
- func (mr MediaRange) String() string
- func (mr MediaRange) SubType() string
- func (mr MediaRange) Type() string
- type Negotiate
- type NegotiateDirective
- type OverrideDirective
- type QualityValue
- func (qv QualityValue) Equals(q QualityValue) bool
- func (qv QualityValue) Float() float32
- func (qv QualityValue) GreaterThan(q QualityValue) bool
- func (qv QualityValue) LessThan(q QualityValue) bool
- func (qv QualityValue) Multiply(q QualityValue) QualityValue
- func (qv QualityValue) Round(scale int) QualityValue
- func (qv QualityValue) String() string
- type ResponseType
- type TCN
- type TCNValue
- type TrueImprovement
Constants ¶
const ( // FeatureExpressionTypeExists indicates the feature expression is testing // for existance of a particular feature. FeatureExpressionTypeExists = iota // FeatureExpressionTypeNotExists indicates the feature expression is // testing for the absence of a particular feature. FeatureExpressionTypeNotExists // FeatureExpressionTypeEquals indicates the feature expression is // testing for a feature with a particular value. FeatureExpressionTypeEquals // FeatureExpressionTypeExclusiveEquals indicates the feature expression is // testing for a feature with a particular value, and only that value. FeatureExpressionTypeExclusiveEquals // FeatureExpressionTypeNotEquals indicates the feature expression is // testing for a feature that doesn't have a particular value. FeatureExpressionTypeNotEquals // FeatureExpressionTypeWildcard indicates the feature expression that // communicates additional features are available, even though they // they weren't mentioned. FeatureExpressionTypeWildcard )
Variables ¶
var ( // DefaultAccept is an Accept header with a single media range of "*/*". DefaultAccept = Accept([]MediaRange{defaultMediaRange}) // EmptyAccept is an empty Accept header. EmptyAccept = Accept([]MediaRange{}) )
var ( // DefaultAcceptCharset is an Accept-Charset header with a charset range // of "*" and quality value of 1.0. DefaultAcceptCharset = AcceptCharset([]CharsetRange{defaultCharsetRange}) // EmptyAcceptCharset is an empty Accept-Charset header. EmptyAcceptCharset = AcceptCharset([]CharsetRange{}) )
var ( // DefaultAcceptEncoding is an Accept-Encoding header value with a // single content coding of "*". DefaultAcceptEncoding = AcceptEncoding([]ContentCodingRange{defaultContentCodingRange}) // EmptyAcceptEncoding is an empty Accept-Encoding header. EmptyAcceptEncoding = AcceptEncoding([]ContentCodingRange{}) )
var ( // DefaultAcceptFeatures is an empty Accept-Features header. DefaultAcceptFeatures = EmptyAcceptFeatures // EmptyAcceptFeatures is an empty Accept-Features header. EmptyAcceptFeatures = AcceptFeatures([]FeatureExpression{}) )
var ( // DefaultAcceptLanguage is an Accept-Language header with a // single language range of "*". DefaultAcceptLanguage = AcceptLanguage([]LanguageRange{defaultLanguageRange}) // EmptyAcceptLanguage is an empty Accept-Language header. EmptyAcceptLanguage = AcceptLanguage([]LanguageRange{}) )
var ( // ErrEmptyCharsetRange is an error that indicates that the charset // range cannot be empty. ErrEmptyCharsetRange = errors.New("charset range cannot be empty") // ErrInvalidCharsetRange is an error that indicates that the charset // range is invalid. ErrInvalidCharsetRange = errors.New("charset range is invalid") )
var ( // ErrEmptyContentCodingRange is an error that indicates that the content // coding range cannot be empty. ErrEmptyContentCodingRange = errors.New("content coding range cannot be empty") // ErrInvalidContentCodingRange is an error that indicates that the content // coding range is invalid. ErrInvalidContentCodingRange = errors.New("content coding range is invalid") )
var ( // ErrInvalidPredicate represents an error that occurs when the // feature predicate is invalid. ErrInvalidPredicate = errors.New("invalid feature predicate") // ErrInvalidPredicateBag represents an error that occurs when the // feature predicate bag is invalid. ErrInvalidPredicateBag = errors.New("invalid feature predicate bag") )
Errors that can be encountered when interacting with feature predicates.
var (
EmptyFeatureSet = FeatureSet(map[FeatureTag][]FeatureTagValue{})
)
var ( // EmptyNegotiateHeader is an empty Negotiate header. EmptyNegotiateHeader = Negotiate([]NegotiateDirective{}) )
var ( // EmptyTCN is an empty TCN header. EmptyTCN = TCN([]TCNValue{}) )
var ( // ErrEmptyLanguageRange is an error that indicates that the langauge // range cannot be empty. ErrEmptyLanguageRange = errors.New("language range cannot be empty") )
var ( // ErrEmptyMediaRange is an error that indicates that the media // range cannot be empty. ErrEmptyMediaRange = errors.New("media range cannot be empty") )
var ( // ErrEmptyNegotiateDirective is an error that indicates that the // negotiate directive cannot be empty. ErrEmptyNegotiateDirective = errors.New("negotiate directive cannot be empty") )
var ( // ErrEmptyTCNValue is an error that indicates that the TCN value cannot // be empty. ErrEmptyTCNValue = errors.New("TCN value cannot be empty") )
var (
ErrInvalidPredicateListElement = errors.New("invalid predicate list element")
)
var ( // ErrInvalidQualityValue is an error that indicates that the quality value must be between 0.0 and 1.0. ErrInvalidQualityValue = errors.New("quality range must be between 0.0 and 1.0") )
Functions ¶
This section is empty.
Types ¶
type Accept ¶
type Accept []MediaRange
Accept represents the Accept header.
The "Accept" header field can be used by user agents to specify response media types that are acceptable. Accept header fields can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.
func (Accept) Compatible ¶
Compatible determines if the provided media type is compatible with any of the media ranges within the Accept header value.
func (Accept) MediaRanges ¶
func (a Accept) MediaRanges() []MediaRange
MediaRanges provides the media ranges sorted on preference and precedence, from highest preference and precedence to lowest.
type AcceptCharset ¶
type AcceptCharset []CharsetRange
AcceptCharset represents the Accept-Charset header.
The "Accept-Charset" header field can be sent by a user agent to indicate what charsets are acceptable in textual response content. This field allows user agents capable of understanding more comprehensive or special-purpose charsets to signal that capability to an origin server that is capable of representing information in those charsets.
func NewAcceptCharset ¶
func NewAcceptCharset(acceptCharset []string) (AcceptCharset, error)
NewAcceptCharset constructs an Accept-Charset header with the provided charsets.
func (AcceptCharset) CharsetRanges ¶
func (c AcceptCharset) CharsetRanges() []CharsetRange
CharsetRanges provides the charsets sorted on preference from highest preference to lowest.
func (AcceptCharset) Compatible ¶
func (c AcceptCharset) Compatible(charset string) (cc bool, err error)
Compatible determines if the provided charset is compatible with any of the charset ranges within the Accept-Charset header value.
func (AcceptCharset) IsEmpty ¶
func (c AcceptCharset) IsEmpty() bool
IsEmpty indicates if the Accept-Charset header is empty.
func (AcceptCharset) String ¶
func (c AcceptCharset) String() string
String provides the textual representation of the Accept-Charset header value.
type AcceptEncoding ¶
type AcceptEncoding []ContentCodingRange
AcceptEncoding represents the Accept-Encoding header.
The "Accept-Encoding" header field can be used by user agents to indicate what response content-codings (Section 3.1.2.1) are acceptable in the response.
func NewAcceptEncoding ¶
func NewAcceptEncoding(acceptEncoding []string) (AcceptEncoding, error)
NewAcceptEncoding constructs an Accept-Encoding header with the provided content codings.
func (AcceptEncoding) CodingRanges ¶
func (e AcceptEncoding) CodingRanges() []ContentCodingRange
Codings provides the content codings sorted on preference from highest preference to lowest.
func (AcceptEncoding) IsEmpty ¶
func (e AcceptEncoding) IsEmpty() bool
IsEmpty indicates if the Accept-Encoding header is empty.
func (AcceptEncoding) String ¶
func (e AcceptEncoding) String() string
String provides a textual representation of the Accept-Encoding header.
type AcceptFeatures ¶
type AcceptFeatures []FeatureExpression
AcceptFeatures represents the Accept-Features header.
The Accept-Features request header can be used by a user agent to give information about the presence or absence of certain features in the feature set of the current request. Servers can use this information when running a remote variant selection algorithm.
func NewAcceptFeatures ¶
func NewAcceptFeatures(acceptFeatures []string) (AcceptFeatures, error)
NewAcceptFeatures constructs an Accept-Features header with the provided feature expressions.
func (AcceptFeatures) AsFeatureSets ¶
func (f AcceptFeatures) AsFeatureSets() (supported, unsupported FeatureSet)
AsFeatureSets utilizes the feature expressions within the Accept-Feature header to construct a partial view of the user agent's supported and unsupported feature sets.
func (AcceptFeatures) IsEmpty ¶
func (f AcceptFeatures) IsEmpty() bool
Empty indicates if the Accept-Header is empty.
func (AcceptFeatures) String ¶
func (f AcceptFeatures) String() string
String provides a textual representation of the Accept-Features header.
type AcceptLanguage ¶
type AcceptLanguage []LanguageRange
AcceptLanguage represents the Accept-Language header.
The "Accept-Language" header field can be used by user agents to indicate the set of natural languages that are preferred in the response. Language tags are defined in Section 3.1.3.1.
func NewAcceptLanguage ¶
func NewAcceptLanguage(acceptLanguage []string) (AcceptLanguage, error)
NewAcceptLanguage constructs an Accept-Language header with the provided language ranges.
func (AcceptLanguage) Compatible ¶
func (l AcceptLanguage) Compatible(language string) (c bool, err error)
Compatible determines if the provided language is compatible with any of the language ranges within the Accept-Language header value.
func (AcceptLanguage) IsEmpty ¶
func (l AcceptLanguage) IsEmpty() bool
IsEmpty indicates if the Accept-Language header is empty.
func (AcceptLanguage) LanguageRanges ¶
func (l AcceptLanguage) LanguageRanges() []LanguageRange
LanguageRanges provides the language ranges sorted on preference from//// highest to lowest.
func (AcceptLanguage) String ¶
func (l AcceptLanguage) String() string
String provides a textual representation of the Accept-Language header.
type Alternates ¶
type Alternates struct {
// contains filtered or unexported fields
}
Alternates represents the Alternates header.
func NewAlternates ¶
func NewAlternates( fb representation.Representation, reps ...representation.Representation) (Alternates, error)
NewAlternates constructs an Alternates header with the provided representations.
func (Alternates) HasFallback ¶
func (a Alternates) HasFallback() bool
HasFallback indicates if a fallback variant has been specified.
func (Alternates) String ¶
func (a Alternates) String() string
String provides the textual representation of the Alternates header value.
func (Alternates) ValuesAsString ¶
func (a Alternates) ValuesAsString() string
ValuesAsString provides a single string containing all of the values for// the Alternates header.
func (Alternates) ValuesAsStrings ¶
func (a Alternates) ValuesAsStrings() []string
ValuesAsStrings provides the string representation for each value of for the Alternates header.
type CharsetRange ¶
type CharsetRange struct {
// contains filtered or unexported fields
}
CharsetRange represents an expression that indicates an encoding transformation.
func NewCharsetRange ¶
func NewCharsetRange(charset string) (CharsetRange, error)
NewCharsetRange constructs a charset from the textual representation.
func (CharsetRange) Charset ¶
func (c CharsetRange) Charset() string
Charset retrieves the range value for the charset range.
func (CharsetRange) Compatible ¶
func (c CharsetRange) Compatible(charset string) bool
Compatible determines if the provided charset is compatible with the charset range.
func (CharsetRange) IsCharset ¶
func (c CharsetRange) IsCharset() bool
IsCharset indicates that the charset range is a charset.
func (CharsetRange) IsWildcard ¶
func (c CharsetRange) IsWildcard() bool
IsWildcard indicates if the charset range is '*'.
func (CharsetRange) QualityValue ¶
func (c CharsetRange) QualityValue() QualityValue
QualityValue retrieves the quality value of the charset range.
func (CharsetRange) String ¶
func (c CharsetRange) String() string
String provides a textual representation of the charset range.
type ContentCodingRange ¶
type ContentCodingRange struct {
// contains filtered or unexported fields
}
ContentCodingRange represents an expression that indicates an encoding transformation.
Content coding values indicate an encoding transformation that has been or can be applied to a representation. Content codings are primarily used to allow a representation to be compressed or otherwise usefully transformed without losing the identity of its underlying media type and without loss of information.
func NewContentCodingRange ¶
func NewContentCodingRange(contentCoding string) (ContentCodingRange, error)
NewContentCodingRange constructs a content coding from the textual representation.
func (ContentCodingRange) CodingRange ¶
func (cc ContentCodingRange) CodingRange() string
Coding retrieves the content coding.
func (ContentCodingRange) Compatible ¶
func (cc ContentCodingRange) Compatible(coding string) bool
Compatible determines if the provided content coding is compatible with the content coding range.
func (ContentCodingRange) IsCoding ¶
func (cc ContentCodingRange) IsCoding() bool
IsCoding indicates if the specified coding range is a content coding.
func (ContentCodingRange) IsIdentity ¶
func (cc ContentCodingRange) IsIdentity() bool
IsIdentity indicates if the specified coding range is 'identi'.
func (ContentCodingRange) IsWildcard ¶
func (cc ContentCodingRange) IsWildcard() bool
IsWildcard indicates if the specified coding range is '*'.
func (ContentCodingRange) QualityValue ¶
func (cc ContentCodingRange) QualityValue() QualityValue
QualityValue retrieves the quality value of the content coding.
Each codings value MAY be given an associated quality value representing the preference for that encoding, as defined in Section 5.3.1.
func (ContentCodingRange) String ¶
func (cc ContentCodingRange) String() string
String provides a textual representation of the content coding.
type FalseDegradation ¶
type FalseDegradation float32
FalseDegradation represents the degradation factor yielded when a feature list element is determined to be false.
func (FalseDegradation) Float ¶
func (fd FalseDegradation) Float() float32
Float provides the floating point representation of the false-degredation factor.
func (FalseDegradation) String ¶
func (fd FalseDegradation) String() string
String provides the textual representation of the false-degradation factor.
type FeatureExpression ¶
type FeatureExpression string
FeatureExpression represents a feature expression communicated in the Accept-Features header.
func (FeatureExpression) HasValue ¶
func (e FeatureExpression) HasValue() bool
HasValue determines if the feature expression has a feature tag value. Existance, absence, and wildcard feature expressions do not have tag values.
func (FeatureExpression) IsExclusive ¶
func (e FeatureExpression) IsExclusive() bool
IsExclusive indicates if the feature expression uses exclusive equality.
func (FeatureExpression) IsWildcard ¶
func (e FeatureExpression) IsWildcard() bool
IsWildcard indicates if the feature expression is '*'.
func (FeatureExpression) String ¶
func (e FeatureExpression) String() string
String provides a textual representation of the feature expression.
func (FeatureExpression) Tag ¶
func (e FeatureExpression) Tag() FeatureTag
Tag retrieves the feature tag for the feature expression, when applicable. Wilcard expressions do not contain a feature tag.
func (FeatureExpression) Type ¶
func (e FeatureExpression) Type() FeatureExpressionType
Type indicates the feature expression type.
func (FeatureExpression) Value ¶
func (e FeatureExpression) Value() FeatureTagValue
Value retrieves the feature tag value for the feature expression, when applicable.
type FeatureExpressionType ¶
type FeatureExpressionType int
FeatureExpressionType indicates the operation the feature expression is performing.pr
func (FeatureExpressionType) String ¶
func (t FeatureExpressionType) String() string
String provides the textual representation of the feature expression type.
type FeatureList ¶
type FeatureList []FeatureListElement
FeatureList represents the collection of feature predicates and feature predicate bags that describe the quality degradation for a particular representation.
func NewFeatureList ¶
func NewFeatureList(features []string) (FeatureList, error)
NewFeatureList constructs a feature list.
func (FeatureList) QualityDegradation ¶
func (fl FeatureList) QualityDegradation(supported, unsupported FeatureSet) float32
QualityDegradation computes the overall quality degradation factor for the feature list based on the provided feature sets.
func (FeatureList) String ¶
func (fl FeatureList) String() string
String provides the textual representation of the feature list.
type FeatureListElement ¶
type FeatureListElement interface { fmt.Stringer TrueImprovement() TrueImprovement FalseDegradation() FalseDegradation // contains filtered or unexported methods }
FeatureListElement represents a single element within a feature list. An element can either be a feature predicate or feature predicate bag.
func NewPredicateBagListElement ¶
func NewPredicateBagListElement(element string) (FeatureListElement, error)
NewPredicateBagListElement constructs a new feature predicate bag list element.
func NewPredicateListElement ¶
func NewPredicateListElement(element string) (FeatureListElement, error)
NewPredicateListElement constructs a new feature predicate list element.
type FeaturePredicate ¶
FeaturePredicate represents a predicate used to express support for a particular feature.
func NewFeaturePredicate ¶
func NewFeaturePredicate(predicate string) (FeaturePredicate, error)
newPredicate constructs a new feature predicate.
type FeaturePredicateBag ¶
type FeaturePredicateBag []FeaturePredicate
FeaturePredicateBag represents a collection of feature predicates.
func NewFeaturePredicateBag ¶
func NewFeaturePredicateBag(predicateBag string) (FeaturePredicateBag, error)
NewFeaturePredicateBag constructs a feature predicate bag.
func (FeaturePredicateBag) Evaluate ¶
func (fpb FeaturePredicateBag) Evaluate(supported, unsupported FeatureSet) bool
Evaluate determines if the predicate bag matches with the provided feature sets.
func (FeaturePredicateBag) String ¶
func (fpb FeaturePredicateBag) String() string
String provides the textual representation of the feature predicate bag.
type FeatureSet ¶
type FeatureSet map[FeatureTag][]FeatureTagValue
FeatureSet represents a collection of feature tags and their values.
func (FeatureSet) Add ¶
func (s FeatureSet) Add(tag FeatureTag, values ...FeatureTagValue)
Add introduces the provides feature tag with the provided values.
func (FeatureSet) Contains ¶
func (s FeatureSet) Contains(tag FeatureTag) (c bool)
Contains determines if the feature set contains the provided feature tag.
func (FeatureSet) String ¶
func (s FeatureSet) String() string
String provides the textual representation of the feature set.
func (FeatureSet) Values ¶
func (s FeatureSet) Values(tag FeatureTag) (v []FeatureTagValue, ok bool)
Values retrieves the values for the provided feature tag.
type FeatureTag ¶
type FeatureTag string
FeatureTag represents a feature tag. https://tools.ietf.org/html/rfc2295#section-6.1
func (FeatureTag) Equals ¶
func (t FeatureTag) Equals(tag FeatureTag) bool
Equals performs a case-insensitive comparison with the provided feature tag. The US-ASCII charset is used for feature tag.
func (FeatureTag) String ¶
func (t FeatureTag) String() string
String provides the textual representation of the feature tag.
type FeatureTagValue ¶
type FeatureTagValue string
FeatureTagValue represents a feature tag value. https://tools.ietf.org/html/rfc2295#section-6.1.1
func (FeatureTagValue) Equals ¶
func (t FeatureTagValue) Equals(val FeatureTagValue) bool
Equals performs a case-sensitive, octect-by-octet comparison with the provided feature tag value. The US-ASCII charset is used for feature tag values.
func (FeatureTagValue) IsNumeric ¶
func (t FeatureTagValue) IsNumeric() bool
IsNumeric indicates if the feature tag value is numeric.
func (FeatureTagValue) String ¶
func (t FeatureTagValue) String() string
String provides the textual representation of the feature tag value.
type LanguageRange ¶
type LanguageRange struct {
// contains filtered or unexported fields
}
LanguageRange represents a language tag matching expression.
func NewLanguageRange ¶
func NewLanguageRange(languageRange string) (LanguageRange, error)
NewLanguageRange constructs a language range from the textual representation.
func (LanguageRange) Compatible ¶
func (lr LanguageRange) Compatible(tag string) bool
Compatible determines if the provided language tag is compatible with the language range.
func (LanguageRange) IsTag ¶
func (lr LanguageRange) IsTag() bool
IsTag indicates if the language range specifies a language tag.
func (LanguageRange) IsWildcard ¶
func (lr LanguageRange) IsWildcard() bool
IsWildcard indicates if the language range is '*'.
func (LanguageRange) QualityValue ¶
func (lr LanguageRange) QualityValue() QualityValue
QualityValue retrieves the quality value of the language range.
func (LanguageRange) String ¶
func (lr LanguageRange) String() string
String provides a textual representation of the language range.
func (LanguageRange) Tag ¶
func (lr LanguageRange) Tag() string
Tag retrieves the language tag this language range specifies.
type MediaRange ¶
type MediaRange struct {
// contains filtered or unexported fields
}
MediaRange represents a media type matching expression.
func NewMediaRange ¶
func NewMediaRange(mediaRange string) (MediaRange, error)
func (MediaRange) Compatible ¶
func (mr MediaRange) Compatible(mediaType string) (bool, error)
Compatible determines if the provided media type is compatible with the media range.
func (MediaRange) HasParams ¶
func (mr MediaRange) HasParams() (b bool)
func (MediaRange) IsSubTypeWildcard ¶
func (mr MediaRange) IsSubTypeWildcard() bool
func (MediaRange) IsTypeWildcard ¶
func (mr MediaRange) IsTypeWildcard() bool
func (MediaRange) Param ¶
func (mr MediaRange) Param(p string) (string, bool)
Param retrieves the value for media range parameter provided.
func (MediaRange) Precedence ¶
func (mr MediaRange) Precedence() int
Precedence determines the specificity of the media range.
func (MediaRange) QualityValue ¶
func (mr MediaRange) QualityValue() QualityValue
QualityValue retrieves the quality value of the media range.
func (MediaRange) String ¶
func (mr MediaRange) String() string
String provides the textual representation of the media range.
func (MediaRange) SubType ¶
func (mr MediaRange) SubType() string
SubType retrieves the subtype of the media range.
func (MediaRange) Type ¶
func (mr MediaRange) Type() string
Type retrieves the type of the media range.
type Negotiate ¶
type Negotiate []NegotiateDirective
Negotiate represents the Negotiate header.
func NewNegotiate ¶
NewNegotiate constructs a Negotiate header with the provided directives.
func (Negotiate) Contains ¶
func (n Negotiate) Contains(directives ...NegotiateDirective) (matches bool)
Contains determines if the Negotiate header contains at least one of the provided directives.
func (Negotiate) ContainsRVSA ¶
ContainsRVSA determines if the Negotiate header contains an RVSA algorithm that matches the version provided.
func (Negotiate) Directives ¶
func (n Negotiate) Directives() []NegotiateDirective
Directives provides the negotiation directives.
type NegotiateDirective ¶
type NegotiateDirective string
NegotiateDirective represents a directive specified within the Negotiate header.
const ( // NegotiateDirectiveTrans indicates the user agent supports transparent // content negotiation for the current request. NegotiateDirectiveTrans NegotiateDirective = "trans" // NegotiateDirectiveVList indicates the user agent requests that any // transparently negotiated response for the current request includes an // Alternates header with the variant list bound to the negotiable resource. NegotiateDirectiveVList NegotiateDirective = "vlist" // NegotiateDirectiveGuessSmall indicates the user agent allows origin // servers to run a custom algorithm which guesses the best variant for // the request, and to return this variant in a choice response, if the // resulting choice response is smaller than or not much larger than a list // response. NegotiateDirectiveGuessSmall NegotiateDirective = "guess-small" )
func NewNegotiateDirective ¶
func NewNegotiateDirective(directive string) (NegotiateDirective, error)
NewNegotiateDirective constructs a new directive for the Negotiate header.
func (NegotiateDirective) IsExtension ¶
func (d NegotiateDirective) IsExtension() bool
IsExtension indicates if the negotiate directive is an extension.
func (NegotiateDirective) IsRVSAVersion ¶
func (d NegotiateDirective) IsRVSAVersion() bool
IsRVSAVersion indicates if the negotiate directive is an RSVA version.
func (NegotiateDirective) IsWildcard ¶
func (d NegotiateDirective) IsWildcard() bool
IsWildcard indicates if the negotiate directive is a wildcard.
func (NegotiateDirective) String ¶
func (d NegotiateDirective) String() string
String provides the textual representation of the TCN value.
type OverrideDirective ¶
type OverrideDirective string
OverrideDirective represents a server-side override performed when producting a response during transparent negotiation.
const ( // OverrideDirectiveReChoose indicates to the user agent it SHOULD use its // internal variant selection algorithm to choose, retrieve, and display // the best variant from this list. OverrideDirectiveReChoose OverrideDirective = "re-choose" // OverrideDirectiveKeep indicates to the user agent it should not renegotiation // on the response to the transparent negotiation request and use it directly. OverrideDirectiveKeep OverrideDirective = "keep" )
func (OverrideDirective) String ¶
func (od OverrideDirective) String() string
String provides the textual representation of the override directive.
type QualityValue ¶
type QualityValue float32
QualityValue represents a relative weight associated with proactive negotiation headers.
Many of the request header fields for proactive negotiation use a common parameter, named "q" (case-insensitive), to assign a relative "weight" to the preference for that associated kind of content. This weight is referred to as a "quality value" (or "qvalue")
const ( // QualityValueMinimum represents the minimum allowed quality value. QualityValueMinimum QualityValue = 0.0 // QualityValueMaximum represents the maximum allowed quality value. QualityValueMaximum QualityValue = 1.0 // QualityValueDefault represents the default quality value when not // specified explicitly. QualityValueDefault QualityValue = QualityValueMaximum )
func NewQualityValue ¶
func NewQualityValue(qvalue float32) (QualityValue, error)
NewQualityValue constructs a new quality value using the provided number.
The weight is normalized to a real number in the range 0 through 1, where 0.001 is the least preferred and 1 is the most preferred; a value of 0 means "not acceptable".
func (QualityValue) Equals ¶
func (qv QualityValue) Equals(q QualityValue) bool
Equals determines if the provided quality value is equivalent.
func (QualityValue) Float ¶
func (qv QualityValue) Float() float32
Float provides the floating point representation of the quality value.
func (QualityValue) GreaterThan ¶
func (qv QualityValue) GreaterThan(q QualityValue) bool
GreaterThan determines if the provided quality value is greater.
func (QualityValue) LessThan ¶
func (qv QualityValue) LessThan(q QualityValue) bool
LessThan determines if the provided quality value is lesser.
func (QualityValue) Multiply ¶
func (qv QualityValue) Multiply(q QualityValue) QualityValue
Multiply multiplies the quality value with the one provided.
func (QualityValue) Round ¶
func (qv QualityValue) Round(scale int) QualityValue
Round rounds the quality value with the scale provided and returns the rounded result.
func (QualityValue) String ¶
func (qv QualityValue) String() string
String provides the textual representation of the quality value.
type ResponseType ¶
type ResponseType string
ResponseType represents the type of transparent negotiation response type.
const ( // ResponseTypeList indicates the response to the transparent negotiation // request contains a list of the available representations. ResponseTypeList ResponseType = "list" // ResponseTypeChoice indicates the response to the transparent negotiation // request contains a chosen representation using a server-side algorithm. ResponseTypeChoice ResponseType = "choice" // ResponseTypeAdhoc indicates the response to the transparent negotiation // request is acting in the interest of achieving compatibility with a // non-negotiation or buggy client. ResponseTypeAdhoc ResponseType = "adhoc" )
func (ResponseType) String ¶
func (rt ResponseType) String() string
String provides the textual representation of the response type.
type TCN ¶
type TCN []TCNValue
TCN represents the TCN header.
func (TCN) ValuesAsString ¶
ValuesAsString provides a single string containing all of the values for the TCN header.
func (TCN) ValuesAsStrings ¶
ValuesAsStrings provides the string representation for each value of for the TCN header.
type TCNValue ¶
type TCNValue string
TCNValue represents a value specified within the TCN header.
func NewTCNValue ¶
NewTCNValue constructs a new value for the TCN header.
func (TCNValue) IsExtension ¶
IsExtension indicates if the TCN value is an extension.
type TrueImprovement ¶
type TrueImprovement float32
TrueImprovement represents the degradation factor yielded when a feature list element is determined to be true.
func (TrueImprovement) Float ¶
func (ti TrueImprovement) Float() float32
Float provides the floating point representation of the true-improvement factor.
func (TrueImprovement) String ¶
func (ti TrueImprovement) String() string
String provides the textual representation of the true-improvement factor.
Source Files ¶
- accept.go
- accept_charset.go
- accept_encoding.go
- accept_features.go
- accept_language.go
- alternates.go
- charset_range.go
- content_coding_range.go
- doc.go
- evaluator.go
- feature_expression.go
- feature_list.go
- feature_list_element.go
- feature_predicate.go
- feature_set.go
- feature_tag.go
- language_range.go
- media_range.go
- negotiate.go
- negotiate_directive.go
- quality_value.go
- tcn.go