Permalink
Browse files

Static middleware accepts cache control.

  • Loading branch information...
1 parent ed3e667 commit e1c16850168fbadc5ae8a0688e23170021a84955 @josevalim josevalim committed May 3, 2011
Showing with 11 additions and 5 deletions.
  1. +4 −4 actionpack/lib/action_dispatch/middleware/static.rb
  2. +7 −1 actionpack/test/dispatch/static_test.rb
View
8 actionpack/lib/action_dispatch/middleware/static.rb
@@ -2,10 +2,10 @@
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 @@ def ext
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)
View
8 actionpack/test/dispatch/static_test.rb
@@ -5,6 +5,12 @@ def test_serves_dynamic_content
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

0 comments on commit e1c1685

Please sign in to comment.