diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-23 19:11:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-23 19:30:23 -0700 |
commit | 6e039e863a5d71f2a516be2eef2605be23281290 (patch) | |
tree | 3039eab02ffe6a58c3a996b4367048d3a92b3410 /actionpack/lib/action_dispatch/http/request.rb | |
parent | a78b0a40c62600767d6ce75ba05bc86d401ad94c (diff) | |
download | rails-6e039e863a5d71f2a516be2eef2605be23281290.tar.gz rails-6e039e863a5d71f2a516be2eef2605be23281290.tar.bz2 rails-6e039e863a5d71f2a516be2eef2605be23281290.zip |
Speed up Request#formats
Diffstat (limited to 'actionpack/lib/action_dispatch/http/request.rb')
-rwxr-xr-x | actionpack/lib/action_dispatch/http/request.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 259164d118..140feb9a68 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -3,7 +3,9 @@ require 'stringio' require 'strscan' require 'active_support/memoizable' +require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/hash/indifferent_access' +require 'active_support/core_ext/object/tap' module ActionDispatch class Request < Rack::Request @@ -173,15 +175,21 @@ module ActionDispatch def formats if ActionController::Base.use_accept_header - ret = Array(Mime[parameters[:format]] || accepts) - if defined?(ActionController::Http) - if all = ret.index(Mime::ALL) - ret.delete(Mime::ALL) && ret.insert(all, *Mime::SET) + if param = parameters[:format] + Array.wrap(Mime[param]) + else + accepts.dup + end.tap do |ret| + if defined?(ActionController::Http) + if ret == ONLY_ALL + ret.replace Mime::SET + elsif all = ret.index(Mime::ALL) + ret.delete_at(all) && ret.insert(all, *Mime::SET) + end end end - ret else - [format] + Mime::SET + [format] + Mime::SET end end |