Skip to content

Commit

Permalink
Merge pull request #20520 from yuki24/use-a-kwarg-for-static-index
Browse files Browse the repository at this point in the history
Change the `index` arg of `ActionDispatch::Static#new` to a kwarg
  • Loading branch information
rafaelfranca committed Jun 11, 2015
2 parents 75761c1 + a888c3c commit b560f87
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions actionpack/lib/action_dispatch/middleware/static.rb
Expand Up @@ -13,15 +13,14 @@ module ActionDispatch
# located at `public/assets/application.js` if the file exists. If the file
# does not exist, a 404 "File not Found" response will be returned.
class FileHandler
def initialize(root, cache_control, index = 'index')
def initialize(root, cache_control, index: 'index')
@root = root.chomp('/')
@compiled_root = /^#{Regexp.escape(root)}/
headers = cache_control && { 'Cache-Control' => cache_control }
@file_server = ::Rack::File.new(@root, headers)
@index = index
end


# Takes a path to a file. If the file is found, has valid encoding, and has
# correct read permissions, the return value is a URI-escaped string
# representing the filename. Otherwise, false is returned.
Expand Down Expand Up @@ -105,9 +104,9 @@ def gzip_file_path(path)
# produce a directory traversal using this middleware. Only 'GET' and 'HEAD'
# requests will result in a file being returned.
class Static
def initialize(app, path, cache_control = nil, index = 'index')
def initialize(app, path, cache_control = nil, index: 'index')
@app = app
@file_handler = FileHandler.new(path, cache_control, index)
@file_handler = FileHandler.new(path, cache_control, index: index)
end

def call(env)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/dispatch/static_test.rb
Expand Up @@ -263,7 +263,7 @@ def test_custom_handler_called_when_file_is_outside_root
end

def test_non_default_static_index
@app = ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60", "other-index")
@app = ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60", index: "other-index")
assert_html "/other-index.html", get("/other-index.html")
assert_html "/other-index.html", get("/other-index")
assert_html "/other-index.html", get("/")
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application/default_middleware_stack.rb
Expand Up @@ -18,7 +18,7 @@ def build_stack
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header

if config.serve_static_files
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control, config.static_index
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control, index: config.static_index
end

if rack_cache = load_rack_cache
Expand Down

0 comments on commit b560f87

Please sign in to comment.