Methods
- A
- C
- F
- N
- U
- V
Constants
BROWSER_LIKE_ACCEPTS | = | /,\s*\*\/\*|\*\/\*\s*,/ |
Instance Public methods
Returns the accepted MIME type for the request.
# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 30 30: def accepts 31: @env["action_dispatch.request.accepts"] ||= begin 32: header = @env['HTTP_ACCEPT'].to_s.strip 33: 34: if header.empty? 35: [content_mime_type] 36: else 37: Mime::Type.parse(header) 38: end 39: end 40: 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 actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 15 15: def content_mime_type 16: @env["action_dispatch.request.content_type"] ||= begin 17: if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/ 18: Mime::Type.lookup($1.strip.downcase) 19: else 20: nil 21: end 22: end 23: 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
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 actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 52 52: def formats 53: @env["action_dispatch.request.formats"] ||= 54: if parameters[:format] 55: Array(Mime[parameters[:format]]) 56: elsif use_accept_header && valid_accept_header 57: accepts 58: elsif xhr? 59: [Mime::JS] 60: else 61: [Mime::HTML] 62: end 63: end
Receives an array of mimes and return the first user sent mime that matches the order array.
# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 84 84: def negotiate_mime(order) 85: formats.each do |priority| 86: if priority == Mime::ALL 87: return order.first 88: elsif order.include?(priority) 89: return priority 90: end 91: end 92: 93: order.include?(Mime::ALL) ? formats.first : nil 94: end
Instance Protected methods