Skip to content

Commit

Permalink
Removed ActionDispatch::FileHandler abstraction.
Browse files Browse the repository at this point in the history
This class was originally added to support multiple file roots.
Since this feature no longer exists, the extra abstraction is unnecessary.
  • Loading branch information
jbaudanza committed Jan 1, 2013
1 parent 56aa02f commit bdcee3e
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions actionpack/lib/action_dispatch/middleware/static.rb
Expand Up @@ -2,10 +2,11 @@
require 'active_support/core_ext/uri'

module ActionDispatch
class FileHandler
def initialize(root, cache_control)
class Static
def initialize(app, root, cache_control=nil)
@app = app
@root = root.chomp('/')
@compiled_root = /^#{Regexp.escape(root)}/
@compiled_root = /^#{Regexp.escape(@root)}/
@file_server = ::Rack::File.new(@root, cache_control)
end

Expand All @@ -24,7 +25,16 @@ def match?(path)
end

def call(env)
@file_server.call(env)
case env['REQUEST_METHOD']
when 'GET', 'HEAD'
path = env['PATH_INFO'].chomp('/')
if match = match?(path)
env["PATH_INFO"] = match
return @file_server.call(env)
end
end

@app.call(env)
end

def ext
Expand All @@ -43,24 +53,4 @@ def escape_glob_chars(path)
path.gsub(/[*?{}\[\]]/, "\\\\\\&")
end
end

class Static
def initialize(app, path, cache_control=nil)
@app = app
@file_handler = FileHandler.new(path, cache_control)
end

def call(env)
case env['REQUEST_METHOD']
when 'GET', 'HEAD'
path = env['PATH_INFO'].chomp('/')
if match = @file_handler.match?(path)
env["PATH_INFO"] = match
return @file_handler.call(env)
end
end

@app.call(env)
end
end
end

0 comments on commit bdcee3e

Please sign in to comment.