Module: ActionDispatch::Http::MimeNegotiation

Defined in:
lib/mime_fallback/mime_negotiation.rb

Instance Method Summary collapse

Instance Method Details

#negotiate_mime(order) ⇒ Object

Override to support mime type fallbacks



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mime_fallback/mime_negotiation.rb', line 9

def negotiate_mime(order)
  formats.each do |priority|
    if priority == Mime::ALL
      return order.first
    else
      # Try to find an exact match to what we're responding to
      types = Array(priority) + MimeFallback::Type.fallbacks(priority.to_sym)
      types.each do |fallback|
        return fallback if order.map(&:to_sym).include?(fallback.to_sym)
      end
      
      if order.include?(priority)
        return priority
      end
    end
  end
  
  order.include?(Mime::ALL) ? formats.first : nil
end