summaryrefslogtreecommitdiff
path: root/lib/rack/utils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rack/utils.rb')
-rw-r--r--lib/rack/utils.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index 0fef215d..f033c900 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -174,17 +174,23 @@ module Rack
def select_best_encoding(available_encodings, accept_encoding)
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
- expanded_accept_encoding =
- accept_encoding.each_with_object([]) do |(m, q), list|
- if m == "*"
- (available_encodings - accept_encoding.map(&:first))
- .each { |m2| list << [m2, q] }
- else
- list << [m, q]
+ expanded_accept_encoding = []
+
+ accept_encoding.each do |m, q|
+ preference = available_encodings.index(m) || available_encodings.size
+
+ if m == "*"
+ (available_encodings - accept_encoding.map(&:first)).each do |m2|
+ expanded_accept_encoding << [m2, q, preference]
end
+ else
+ expanded_accept_encoding << [m, q, preference]
end
+ end
- encoding_candidates = expanded_accept_encoding.sort_by { |_, q| -q }.map!(&:first)
+ encoding_candidates = expanded_accept_encoding
+ .sort_by { |_, q, p| [-q, p] }
+ .map!(&:first)
unless encoding_candidates.include?("identity")
encoding_candidates.push("identity")