diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-12-04 17:40:54 -0500 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-12-09 16:14:57 +0100 |
commit | 0027b654215cd6310d0d17daeaafec8ebbfb38d4 (patch) | |
tree | 6a15b97f4e9a04f01b516fcab0e6dae48ba0c7f9 /actionpack/lib | |
parent | cc48192248f107c61294f72459fd027d45403ba5 (diff) | |
download | rails-0027b654215cd6310d0d17daeaafec8ebbfb38d4.tar.gz rails-0027b654215cd6310d0d17daeaafec8ebbfb38d4.tar.bz2 rails-0027b654215cd6310d0d17daeaafec8ebbfb38d4.zip |
Ensure that while caching a page rails takes into
account the resolved mime type for the request
[#6110 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/caching/pages.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index 104157d0b1..3e57d2c236 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -70,9 +70,9 @@ module ActionController #:nodoc: # Manually cache the +content+ in the key determined by +path+. Example: # cache_page "I'm the cached content", "/lists/show" - def cache_page(content, path) + def cache_page(content, path, extension = nil) return unless perform_caching - path = page_cache_path(path) + path = page_cache_path(path, extension) instrument_page_cache :write_page, path do FileUtils.makedirs(File.dirname(path)) @@ -97,14 +97,16 @@ module ActionController #:nodoc: end private - def page_cache_file(path) + def page_cache_file(path, extension) name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/')) - name << page_cache_extension unless (name.split('/').last || name).include? '.' + unless (name.split('/').last || name).include? '.' + name << (extension || self.page_cache_extension) + end return name end - def page_cache_path(path) - page_cache_directory + page_cache_file(path) + def page_cache_path(path, extension = nil) + page_cache_directory + page_cache_file(path, extension) end def instrument_page_cache(name, path) @@ -145,7 +147,11 @@ module ActionController #:nodoc: request.path end - self.class.cache_page(content || response.body, path) + if (type = Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present? + extension = ".#{type_symbol}" + end + + self.class.cache_page(content || response.body, path, extension) end end |