module ActionDispatch::Http::MimeNegotiation

Public Instance Methods

negotiate_mime(order) click to toggle source

Override to support mime type fallbacks

# File lib/mime_fallback/mime_negotiation.rb, line 9
def negotiate_mime(order)
  # make search easier later
  responding_formats = order.index_by(&:to_sym)

  # formats are the request's formats
  formats.each do |priority|
    return order.first if priority == Mime::ALL

    # Try to find an exact match to what we're responding to
    types = Array(priority) + MimeFallback::Type.fallbacks(priority.to_sym)
    fallback = types.detect{|type| responding_formats.has_key?(type.to_sym)}
    return fallback if fallback

    # we've found an exact match
    return priority if responding_formats.has_key?(priority.to_sym)
  end

  order.include?(Mime::ALL) ? formats.first : nil
end