Methods
A
C
F
N
U
V
Constants
BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/
Instance Public methods
accepts()

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
content_mime_type()

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
content_type()
    # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 25
25:       def content_type
26:         content_mime_type && content_mime_type.to_s
27:       end
format(view_path = [])

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
    # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 48
48:       def format(view_path = [])
49:         formats.first
50:       end
format=(extension)

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 76
76:       def format=(extension)
77:         parameters[:format] = extension.to_s
78:         @env["action_dispatch.request.formats"] = [Mime::Type.lookup_by_extension(parameters[:format])]
79:       end
formats()
    # 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
negotiate_mime(order)

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
use_accept_header()
     # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 105
105:       def use_accept_header
106:         !self.class.ignore_accept_header
107:       end
valid_accept_header()
     # File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 100
100:       def valid_accept_header
101:         (xhr? && (accept || content_mime_type)) ||
102:           (accept && accept !~ BROWSER_LIKE_ACCEPTS)
103:       end