abstract class Athena::Negotiation::AbstractNegotiator(HeaderType)

Overview

Base negotiator type. Implements logic common to all negotiators.

Direct Known Subclasses

Defined in:

abstract_negotiator.cr

Instance Method Summary

Instance Method Detail

def best(header : String, priorities : Indexable(String), strict : Bool = false) : HeaderType | Nil #

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]
def 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]