diff --git a/docs/README.md b/docs/README.md index c5ef2b6..94b03ef 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,12 +24,12 @@ Each negotiator exposes two methods: [ANG::AbstractNegotiator#best][] and [ANG:: negotiator = ANG.negotiator accept_header = "text/html, application/xhtml+xml, application/xml;q=0.9" -priorities = ["text/html; charset=UTF-8", "application/json", "application/xml;q=0.5"] +priorities = ["text/html; charset=utf-8", "application/json", "application/xml;q=0.5"] accept = negotiator.best(accept_header, priorities).not_nil! accept.media_range # => "text/html" -accept.parameters # => {"charset" => "UTF-8"} +accept.parameters # => {"charset" => "utf-8"} ``` The [ANG::Negotiator][] type returns an [ANG::Accept][], or `nil` if negotiating the best media type has failed. @@ -39,7 +39,7 @@ The [ANG::Negotiator][] type returns an [ANG::Accept][], or `nil` if negotiating ```crystal negotiator = ANG.charset_negotiator -accept_header = "ISO-8859-1, UTF-8; q=0.9" +accept_header = "ISO-8859-1, utf-8; q=0.9" priorities = ["iso-8859-1;q=0.3", "utf-8;q=0.9", "utf-16;q=1.0"] accept = negotiator.best(accept_header, priorities).not_nil! diff --git a/spec/negotiator_spec.cr b/spec/negotiator_spec.cr index f267d92..353942d 100644 --- a/spec/negotiator_spec.cr +++ b/spec/negotiator_spec.cr @@ -71,9 +71,9 @@ struct NegotiatorTest < NegotiatorTestCase {"image/png, text/plain, audio/ogg", {"baz/asdf"}, nil}, {"image/png, text/plain, audio/ogg", {"audio/ogg"}, {"audio/ogg", nil}}, {"image/png, text/plain, audio/ogg", {"YO/SuP"}, nil}, - {"text/html; charset=UTF-8, application/pdf", {"text/html; charset=UTF-8"}, {"text/html", {"charset" => "UTF-8"}}}, - {"text/html; charset=UTF-8, application/pdf", {"text/html"}, nil}, - {"text/html, application/pdf", {"text/html; charset=UTF-8"}, {"text/html", {"charset" => "UTF-8"}}}, + {"text/html; charset=utf-8, application/pdf", {"text/html; charset=utf-8"}, {"text/html", {"charset" => "utf-8"}}}, + {"text/html; charset=utf-8, application/pdf", {"text/html"}, nil}, + {"text/html, application/pdf", {"text/html; charset=utf-8"}, {"text/html", {"charset" => "utf-8"}}}, # PHP"s PEAR HTTP2 assertions I took from the other lib. {php_pear_header, {"image/gif", "image/png", "application/xhtml+xml", "application/xml", "text/html", "image/jpeg", "text/plain"}, {"image/png", nil}}, diff --git a/src/abstract_negotiator.cr b/src/abstract_negotiator.cr index 0f67a51..1bddf8c 100644 --- a/src/abstract_negotiator.cr +++ b/src/abstract_negotiator.cr @@ -26,9 +26,9 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) raise ex if strict end - accepted_priorties = priorities.map { |p| HeaderType.new p } + accepted_priorities = priorities.map { |p| HeaderType.new p } - matches = self.find_matches accepted_headers, accepted_priorties + matches = self.find_matches accepted_headers, accepted_priorities specific_matches = matches.reduce({} of Int32 => ANG::AcceptMatch) do |acc, match| ANG::AcceptMatch.reduce acc, match @@ -38,7 +38,7 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) match = specific_matches.shift? - match.nil? ? nil : accepted_priorties[match.index] + match.nil? ? nil : accepted_priorities[match.index] end # Returns an array of `HeaderType` that the provided *header* allows, ordered so that the `#best` match is first. diff --git a/src/accept.cr b/src/accept.cr index 8a4b6df..d69e91a 100644 --- a/src/accept.cr +++ b/src/accept.cr @@ -3,11 +3,11 @@ require "./base_accept" # Represents an [Accept](https://tools.ietf.org/html/rfc7231#section-5.3.2) header media type. # # ``` -# accept = ANG::Accept.new "application/json; q = 0.75; charset = UTF-8" +# accept = ANG::Accept.new "application/json; q = 0.75; charset = utf-8" # -# accept.header # => "application/json; q = 0.75; charset = UTF-8" -# accept.normalized_header # => "application/json; charset=UTF-8" -# accept.parameters # => {"charset" => "UTF-8"} +# accept.header # => "application/json; q = 0.75; charset = utf-8" +# accept.normalized_header # => "application/json; charset=utf-8" +# accept.parameters # => {"charset" => "utf-8"} # accept.quality # => 0.75 # accept.type # => "application" # accept.sub_type # => "json" diff --git a/src/base_accept.cr b/src/base_accept.cr index f11d50e..b9e02b8 100644 --- a/src/base_accept.cr +++ b/src/base_accept.cr @@ -10,7 +10,7 @@ abstract struct Athena::Negotiation::BaseAccept getter normalized_header : String # Returns any extension parameters included in the header `self` represents. - # E.x. `charset=UTF-8` or `version=2`. + # E.x. `charset=utf-8` or `version=2`. getter parameters : Hash(String, String) = Hash(String, String).new # Returns the [quality value](https://tools.ietf.org/html/rfc7231#section-5.3.1) of the header `self` represents.