aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/mime_type.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch/http/mime_type.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb43
1 files changed, 16 insertions, 27 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 6abbf9c754..463b5fe405 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -106,27 +106,33 @@ module Mime
result = @index <=> item.index if result == 0
result
end
-
- def ==(item)
- @name == item.to_s
- end
end
class AcceptList < Array #:nodoc:
def assort!
sort!
+ text_xml_idx = find_item_by_name self, 'text/xml'
+ app_xml_idx = find_item_by_name self, Mime[:xml].to_s
+
# Take care of the broken text/xml entry by renaming or deleting it
if text_xml_idx && app_xml_idx
+ app_xml = self[app_xml_idx]
+ text_xml = self[text_xml_idx]
+
app_xml.q = [text_xml.q, app_xml.q].max # set the q value to the max of the two
- exchange_xml_items if app_xml_idx > text_xml_idx # make sure app_xml is ahead of text_xml in the list
+ if app_xml_idx > text_xml_idx # make sure app_xml is ahead of text_xml in the list
+ self[app_xml_idx], self[text_xml_idx] = text_xml, app_xml
+ app_xml_idx, text_xml_idx = text_xml_idx, app_xml_idx
+ end
delete_at(text_xml_idx) # delete text_xml from the list
elsif text_xml_idx
- text_xml.name = Mime[:xml].to_s
+ self[text_xml_idx].name = Mime[:xml].to_s
end
# Look for more specific XML-based types and sort them ahead of app/xml
if app_xml_idx
+ app_xml = self[app_xml_idx]
idx = app_xml_idx
while idx < length
@@ -135,7 +141,7 @@ module Mime
if type.name.ends_with? '+xml'
self[app_xml_idx], self[idx] = self[idx], app_xml
- @app_xml_idx = idx
+ app_xml_idx = idx
end
idx += 1
end
@@ -146,26 +152,9 @@ module Mime
end
private
- def text_xml_idx
- @text_xml_idx ||= index('text/xml')
- end
-
- def app_xml_idx
- @app_xml_idx ||= index(Mime[:xml].to_s)
- end
-
- def text_xml
- self[text_xml_idx]
- end
-
- def app_xml
- self[app_xml_idx]
- end
-
- def exchange_xml_items
- self[app_xml_idx], self[text_xml_idx] = text_xml, app_xml
- @app_xml_idx, @text_xml_idx = text_xml_idx, app_xml_idx
- end
+ def find_item_by_name(array, name)
+ array.index { |item| item.name == name }
+ end
end
class << self