aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-03-09 23:31:04 -0500
committerJoshua Peek <josh@joshpeek.com>2009-03-09 23:31:04 -0500
commit0c9bbf8c9dca46fbd7916640c417d13bf8b5af30 (patch)
treeb3440679b8db82709d2056d3fd265eb181c76663 /railties/lib/rails
parent224a534400fd622dda57058d1eed349b8375e5e3 (diff)
downloadrails-0c9bbf8c9dca46fbd7916640c417d13bf8b5af30.tar.gz
rails-0c9bbf8c9dca46fbd7916640c417d13bf8b5af30.tar.bz2
rails-0c9bbf8c9dca46fbd7916640c417d13bf8b5af30.zip
Fix serving index files with rack static file server [#2180 state:resolved]
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/rack/static.rb17
1 files changed, 13 insertions, 4 deletions
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