diff options
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 4 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index e57339b3aa..9c4fe63ab0 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -48,6 +48,10 @@ module Mime LOOKUP[string] end + def lookup_by_extension(extension) + EXTENSION_LOOKUP[extension] + end + def register(string, symbol, mime_type_synonyms = [], extension_synonyms = []) Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms) diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 98d28d24b8..8c21adb8df 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -83,6 +83,16 @@ module ActionController end end + # Returns the Mime type for the format used in the request. If there is no format available, the first of the + # accept types will be used. Examples: + # + # GET /posts/5.xml | request.format => Mime::XML + # GET /posts/5.xhtml | request.format => Mime::HTML + # GET /posts/5 | request.format => request.accepts.first (usually Mime::HTML for browsers) + def format + parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first + end + # Returns true if the request's "X-Requested-With" header contains # "XMLHttpRequest". (The Prototype Javascript library sends this header with # every Ajax request.) |