diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-03 12:32:14 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-03 12:32:14 +0200 |
commit | e1c16850168fbadc5ae8a0688e23170021a84955 (patch) | |
tree | fe56bef3d06b05dcebcca8d5a323bcb88e355889 | |
parent | ed3e667415e191d1677a3b7e55b077f55504214c (diff) | |
download | rails-e1c16850168fbadc5ae8a0688e23170021a84955.tar.gz rails-e1c16850168fbadc5ae8a0688e23170021a84955.tar.bz2 rails-e1c16850168fbadc5ae8a0688e23170021a84955.zip |
Static middleware accepts cache control.
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/static.rb | 8 | ||||
-rw-r--r-- | actionpack/test/dispatch/static_test.rb | 8 |
2 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 348f7b86b8..360c1209bb 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -2,10 +2,10 @@ require 'rack/utils' module ActionDispatch class FileHandler - def initialize(root) + def initialize(root, cache_control) @root = root.chomp('/') @compiled_root = /^#{Regexp.escape(root)}/ - @file_server = ::Rack::File.new(@root) + @file_server = ::Rack::File.new(@root, cache_control) end def match?(path) @@ -37,9 +37,9 @@ module ActionDispatch class Static FILE_METHODS = %w(GET HEAD).freeze - def initialize(app, path) + def initialize(app, path, cache_control=nil) @app = app - @file_handler = FileHandler.new(path) + @file_handler = FileHandler.new(path, cache_control) end def call(env) diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index 2ebbed4414..9f3cbd19ef 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -5,6 +5,12 @@ module StaticTests assert_equal "Hello, World!", get("/nofile").body end + def test_sets_cache_control + response = get("/index.html") + assert_html "/index.html", response + assert_equal "public, max-age=60", response.headers["Cache-Control"] + end + def test_serves_static_index_at_root assert_html "/index.html", get("/index.html") assert_html "/index.html", get("/index") @@ -40,7 +46,7 @@ class StaticTest < ActiveSupport::TestCase DummyApp = lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] } - App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public") + App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public", "public, max-age=60") def setup @app = App |