Returns the accepted MIME type for the request.
# File lib/action_dispatch/http/mime_negotiation.rb, line 23 23: def accepts 24: @env["action_dispatch.request.accepts"] ||= begin 25: header = @env['HTTP_ACCEPT'].to_s.strip 26: 27: if header.empty? 28: [content_mime_type] 29: else 30: Mime::Type.parse(header) 31: end 32: end 33: end
The MIME type of the HTTP request, such as Mime::XML.
For backward compatibility, the post format is extracted from the X-Post-Data-Format HTTP header if present.
# File lib/action_dispatch/http/mime_negotiation.rb, line 8 8: def content_mime_type 9: @env["action_dispatch.request.content_type"] ||= begin 10: if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/ 11: Mime::Type.lookup($1.strip.downcase) 12: else 13: nil 14: end 15: end 16: end
# File lib/action_dispatch/http/mime_negotiation.rb, line 18 18: def content_type 19: content_mime_type && content_mime_type.to_s 20: end
Returns the MIME type for the format used in the request.
GET /posts/5.xml | request.format => Mime::XML GET /posts/5.xhtml | request.format => Mime::HTML GET /posts/5 | request.format => Mime::HTML or MIME::JS, or request.accepts.first depending on the value of <tt>ActionController::Base.use_accept_header</tt>
# File lib/action_dispatch/http/mime_negotiation.rb, line 41 41: def format(view_path = []) 42: formats.first 43: end
Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension.
class ApplicationController < ActionController::Base before_filter :adjust_format_for_iphone private def adjust_format_for_iphone request.format = :iphone if request.env["HTTP_USER_AGENT"][/iPhone/] end end
# File lib/action_dispatch/http/mime_negotiation.rb, line 69 69: def format=(extension) 70: parameters[:format] = extension.to_s 71: @env["action_dispatch.request.formats"] = [Mime::Type.lookup_by_extension(parameters[:format])] 72: end
# File lib/action_dispatch/http/mime_negotiation.rb, line 45 45: def formats 46: accept = @env['HTTP_ACCEPT'] 47: 48: @env["action_dispatch.request.formats"] ||= 49: if parameters[:format] 50: Array(Mime[parameters[:format]]) 51: elsif xhr? || (accept && accept !~ /,\s*\*\/\*/) 52: accepts 53: else 54: [Mime::HTML] 55: end 56: end
Receives an array of mimes and return the first user sent mime that matches the order array.
# File lib/action_dispatch/http/mime_negotiation.rb, line 77 77: def negotiate_mime(order) 78: formats.each do |priority| 79: if priority == Mime::ALL 80: return order.first 81: elsif order.include?(priority) 82: return priority 83: end 84: end 85: 86: order.include?(Mime::ALL) ? formats.first : nil 87: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.