Skip to content

Commit

Permalink
Merge pull request #1980 from alphagov/asset-manage-redirect
Browse files Browse the repository at this point in the history
Ensure asset-manager redirects are cached
  • Loading branch information
thomasleese authored Jan 14, 2021
2 parents 5fc1079 + 273ddcd commit d59384c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/asset_manager_redirect_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/controllers/asset_manager_redirect_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit d59384c

Please sign in to comment.