diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-07-31 16:21:07 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-07-31 16:21:07 -0300 |
commit | 3de59e916d6a3d4eab202cf0c99b1f88905a3b43 (patch) | |
tree | def6d6a808ebe187be1f37f8a739fd786cc11f02 /actionpack/lib/action_dispatch | |
parent | c1cbf02e3170f1004daf4a146cbc41176c2458d3 (diff) | |
parent | 62fd1d3716b4b5fd1d91cdcc77003efe80fc5a7e (diff) | |
download | rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.tar.gz rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.tar.bz2 rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.zip |
Merge commit 'rails/master'
Conflicts:
activerecord/lib/active_record/associations.rb
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_types.rb | 6 | ||||
-rwxr-xr-x | actionpack/lib/action_dispatch/http/request.rb | 42 |
3 files changed, 39 insertions, 11 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 27f27e27fe..cc989d6625 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -84,7 +84,7 @@ module Mime end def lookup_by_extension(extension) - EXTENSION_LOOKUP[extension] + EXTENSION_LOOKUP[extension.to_s] end # Registers an alias that's not used on mime type lookup, but can be referenced directly. Especially useful for diff --git a/actionpack/lib/action_dispatch/http/mime_types.rb b/actionpack/lib/action_dispatch/http/mime_types.rb index 7c28cac419..68f37d2f65 100644 --- a/actionpack/lib/action_dispatch/http/mime_types.rb +++ b/actionpack/lib/action_dispatch/http/mime_types.rb @@ -2,7 +2,6 @@ # http://www.iana.org/assignments/media-types/ Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml ) -Mime::Type.register "*/*", :all Mime::Type.register "text/plain", :text, [], %w(txt) Mime::Type.register "text/javascript", :js, %w( application/javascript application/x-javascript ) Mime::Type.register "text/css", :css @@ -18,4 +17,7 @@ Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form # http://www.ietf.org/rfc/rfc4627.txt # http://www.json.org/JSONRequest.html -Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest )
\ No newline at end of file +Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest ) + +# Create Mime::ALL but do not add it to the SET. +Mime::ALL = Mime::Type.new("*/*", :all, []) diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 3f23a5af7a..5f9463eb91 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -161,7 +161,7 @@ module ActionDispatch # 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> - + # def format(view_path = []) @env["action_dispatch.request.format"] ||= if parameters[:format] @@ -173,13 +173,11 @@ module ActionDispatch end end + # Expand raw_formats by converting Mime::ALL to the Mime::SET. + # def formats if ActionController::Base.use_accept_header - if param = parameters[:format] - Array.wrap(Mime[param]) - else - accepts.dup - end.tap do |ret| + raw_formats.tap do |ret| if ret == ONLY_ALL ret.replace Mime::SET elsif all = ret.index(Mime::ALL) @@ -187,7 +185,7 @@ module ActionDispatch end end else - [format] + Mime::SET + raw_formats + Mime::SET end end @@ -232,7 +230,7 @@ module ActionDispatch def xml_http_request? !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/i) end - alias xhr? :xml_http_request? + alias :xhr? :xml_http_request? # Which IP addresses are "trusted proxies" that can be stripped from # the right-hand-side of X-Forwarded-For @@ -485,7 +483,35 @@ EOM session['flash'] || {} end + # Receives an array of mimes and return the first user sent mime that + # matches the order array. + # + def negotiate_mime(order) + raw_formats.each do |priority| + if priority == Mime::ALL + return order.first + elsif order.include?(priority) + return priority + end + end + + order.include?(Mime::ALL) ? formats.first : nil + end + private + + def raw_formats + if ActionController::Base.use_accept_header + if param = parameters[:format] + Array.wrap(Mime[param]) + else + accepts.dup + end + else + [format] + end + end + def named_host?(host) !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host)) end |