diff options
author | James Tucker <jftucker@gmail.com> | 2014-07-05 16:56:31 -0700 |
---|---|---|
committer | James Tucker <jftucker@gmail.com> | 2014-07-05 16:56:31 -0700 |
commit | 186e256bf0853975e1cad95b1af888e8fe9ef9f5 (patch) | |
tree | 58ab7c9c8c8d05038bb88c30f51955161911cc6c | |
parent | f5dc46af7c97fab406aff4a29d33665ae603e2bd (diff) | |
parent | e06a25423979e0443e6252cbe0cb4b2b41fa89f0 (diff) | |
download | rack-186e256bf0853975e1cad95b1af888e8fe9ef9f5.tar.gz |
Merge pull request #659 from jodosha/utils-best_q_match-respect-content-type
Ensure Rack::Utils.best_q_match to respect requested content type
-rw-r--r-- | lib/rack/utils.rb | 2 | ||||
-rw-r--r-- | test/spec_utils.rb | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 28e0ded6..a8cf7cc1 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -185,7 +185,7 @@ module Rack values = q_values(q_value_header) values.map do |req_mime, quality| - match = available_mimes.first { |am| Rack::Mime.match?(am, req_mime) } + match = available_mimes.find { |am| Rack::Mime.match?(am, req_mime) } next unless match [match, quality] end.compact.sort_by do |match, quality| diff --git a/test/spec_utils.rb b/test/spec_utils.rb index c3867965..b79ae1df 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -300,6 +300,9 @@ describe Rack::Utils do # Higher quality matches are preferred Rack::Utils.best_q_match("text/*;q=0.5,text/plain;q=1.0", %w[text/plain text/html]).should.equal "text/plain" + # Respect requested content type + Rack::Utils.best_q_match("application/json", %w[application/vnd.lotus-1-2-3 application/json]).should.equal "application/json" + # All else equal, the available mimes are preferred in order Rack::Utils.best_q_match("text/*", %w[text/html text/plain]).should.equal "text/html" Rack::Utils.best_q_match("text/plain,text/html", %w[text/html text/plain]).should.equal "text/html" |