Use utf-8 as lowercase is preferred (#417)

This commit is contained in:
George Dietrich 2024-05-24 10:12:32 -04:00 committed by GitHub
parent f6a843890f
commit d821e33839
4 changed files with 11 additions and 11 deletions

View file

@ -24,12 +24,12 @@ Each negotiator exposes two methods: [ANG::AbstractNegotiator#best][] and [ANG::
negotiator = ANG.negotiator negotiator = ANG.negotiator
accept_header = "text/html, application/xhtml+xml, application/xml;q=0.9" 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 = negotiator.best(accept_header, priorities).not_nil!
accept.media_range # => "text/html" 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. 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 ```crystal
negotiator = ANG.charset_negotiator 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"] 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! accept = negotiator.best(accept_header, priorities).not_nil!

View file

@ -71,9 +71,9 @@ struct NegotiatorTest < NegotiatorTestCase
{"image/png, text/plain, audio/ogg", {"baz/asdf"}, nil}, {"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", {"audio/ogg"}, {"audio/ogg", nil}},
{"image/png, text/plain, audio/ogg", {"YO/SuP"}, 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; charset=utf-8"}, {"text/html", {"charset" => "utf-8"}}},
{"text/html; charset=UTF-8, application/pdf", {"text/html"}, nil}, {"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, application/pdf", {"text/html; charset=utf-8"}, {"text/html", {"charset" => "utf-8"}}},
# PHP"s PEAR HTTP2 assertions I took from the other lib. # 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}}, {php_pear_header, {"image/gif", "image/png", "application/xhtml+xml", "application/xml", "text/html", "image/jpeg", "text/plain"}, {"image/png", nil}},

View file

@ -3,11 +3,11 @@ require "./base_accept"
# Represents an [Accept](https://tools.ietf.org/html/rfc7231#section-5.3.2) header media type. # 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.header # => "application/json; q = 0.75; charset = utf-8"
# accept.normalized_header # => "application/json; charset=UTF-8" # accept.normalized_header # => "application/json; charset=utf-8"
# accept.parameters # => {"charset" => "UTF-8"} # accept.parameters # => {"charset" => "utf-8"}
# accept.quality # => 0.75 # accept.quality # => 0.75
# accept.type # => "application" # accept.type # => "application"
# accept.sub_type # => "json" # accept.sub_type # => "json"

View file

@ -10,7 +10,7 @@ abstract struct Athena::Negotiation::BaseAccept
getter normalized_header : String getter normalized_header : String
# Returns any extension parameters included in the header `self` represents. # 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 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. # Returns the [quality value](https://tools.ietf.org/html/rfc7231#section-5.3.1) of the header `self` represents.