Skip to content

Commit

Permalink
Ensure asset-manager redirects are cached
Browse files Browse the repository at this point in the history
At the moment these redirects aren't cached which means that they won't
be cached by Fastly and will always hit our origin. This PR should
prevent this from happening and instead they'll be cached by Fastly for
1 day.
  • Loading branch information
thomasleese committed Jan 14, 2021
1 parent 5fc1079 commit 273ddcd
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 273ddcd

Please sign in to comment.