diff --git a/app/controllers/asset_manager_redirect_controller.rb b/app/controllers/asset_manager_redirect_controller.rb index fc877b585..942e762d8 100644 --- a/app/controllers/asset_manager_redirect_controller.rb +++ b/app/controllers/asset_manager_redirect_controller.rb @@ -5,6 +5,7 @@ def show asset_url = Plek.new.external_url_for("draft-assets") end + expires_in 1.day, public: true redirect_to host: URI.parse(asset_url).host, status: :moved_permanently end end diff --git a/test/controllers/asset_manager_redirect_controller_test.rb b/test/controllers/asset_manager_redirect_controller_test.rb index a013a984a..61b87e5f3 100644 --- a/test/controllers/asset_manager_redirect_controller_test.rb +++ b/test/controllers/asset_manager_redirect_controller_test.rb @@ -6,6 +6,13 @@ class AssetManagerRedirectControllerTest < ActionController::TestCase Plek.any_instance.stubs(:external_url_for).returns("http://draft-asset-host.com") end + test "sets the cache-control max-age to 1 day" do + request.host = "some-host.com" + get :show, params: { path: "asset.txt" } + + assert_equal @response.headers["Cache-Control"], "max-age=86400, public" + end + test "redirects asset requests made via public host to the public asset host" do request.host = "some-host.com" get :show, params: { path: "asset.txt" }