Skip to content

abstract class Athena::Negotiation::AbstractNegotiator(HeaderType)
inherits Reference #

Base negotiator type. Implements logic common to all negotiators.

Direct known subclasses

Athena::Negotiation::CharsetNegotiator Athena::Negotiation::EncodingNegotiator Athena::Negotiation::LanguageNegotiator Athena::Negotiation::Negotiator


#best(header : String, priorities : Indexable(String), strict : Bool = false) : HeaderType? #

Returns the best HeaderType based on the provided header value and priorities.

If strict is true, an ANG::Exceptions::Exception will be raised if the header contains an invalid value, otherwise it is ignored.

See Athena::Negotiation for examples.

View source

#ordered_elements(header : String) : Array(HeaderType) #

Returns an array of HeaderType that the provided header allows, ordered so that the #best match is first.

header = "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"

ordered_elements = ANG.negotiator.ordered_elements header

ordered_elements[0].media_range # => "text/html"
ordered_elements[1].media_range # => "text/html"
ordered_elements[2].media_range # => "*/*"
ordered_elements[3].media_range # => "text/html"
ordered_elements[4].media_range # => "text/*"
View source