From 0c9bbf8c9dca46fbd7916640c417d13bf8b5af30 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Mar 2009 23:31:04 -0500 Subject: Fix serving index files with rack static file server [#2180 state:resolved] --- railties/lib/rails/rack/static.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb index ef4e2642e2..f07c6beb5e 100644 --- a/railties/lib/rails/rack/static.rb +++ b/railties/lib/rails/rack/static.rb @@ -13,14 +13,18 @@ module Rails def call(env) path = env['PATH_INFO'].chomp('/') method = env['REQUEST_METHOD'] - cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension if FILE_METHODS.include?(method) if file_exist?(path) return @file_server.call(env) - elsif file_exist?(cached_path) - env['PATH_INFO'] = cached_path - return @file_server.call(env) + else + cached_path = directory_exist?(path) ? "#{path}/index" : path + cached_path += ::ActionController::Base.page_cache_extension + + if file_exist?(cached_path) + env['PATH_INFO'] = cached_path + return @file_server.call(env) + end end end @@ -32,6 +36,11 @@ module Rails full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path)) File.file?(full_path) && File.readable?(full_path) end + + def directory_exist?(path) + full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path)) + File.directory?(full_path) && File.readable?(full_path) + end end end end -- cgit v1.2.3