diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-02 23:33:58 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-02 23:38:57 +0200 |
commit | 73c94ed97ab6639d06dade1738aa5b9f49294340 (patch) | |
tree | 8f63ad355c2dbcb893be4bf8097a857fccc4f4dd /actionpack/lib | |
parent | 79a9bebcbf53673cab5d588869819702ac5a9607 (diff) | |
download | rails-73c94ed97ab6639d06dade1738aa5b9f49294340.tar.gz rails-73c94ed97ab6639d06dade1738aa5b9f49294340.tar.bz2 rails-73c94ed97ab6639d06dade1738aa5b9f49294340.zip |
Add ignore_accept_header config to AD::Request.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_negotiation.rb | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index 68ba1a81b5..980c658ab7 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -1,6 +1,13 @@ module ActionDispatch module Http module MimeNegotiation + extend ActiveSupport::Concern + + included do + mattr_accessor :ignore_accept_header + self.ignore_accept_header = false + end + # The MIME type of the HTTP request, such as Mime::XML. # # For backward compatibility, the post \format is extracted from the @@ -42,16 +49,14 @@ module ActionDispatch formats.first end - BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/ - def formats - accept = @env['HTTP_ACCEPT'] - @env["action_dispatch.request.formats"] ||= if parameters[:format] Array(Mime[parameters[:format]]) - elsif xhr? || (accept && accept !~ BROWSER_LIKE_ACCEPTS) + elsif use_accept_header && valid_accept_header accepts + elsif xhr? + [Mime::JS] else [Mime::HTML] end @@ -87,6 +92,18 @@ module ActionDispatch order.include?(Mime::ALL) ? formats.first : nil end + + protected + + BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/ + + def valid_accept_header + xhr? || (accept && accept !~ BROWSER_LIKE_ACCEPTS) + end + + def use_accept_header + !self.class.ignore_accept_header + end end end end |