mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Enable browser caching for blobs and variants (#30196)
This commit is contained in:
parent
de80aa6412
commit
e25466b142
3 changed files with 17 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
class ActiveStorage::BlobsController < ActionController::Base
|
||||
def show
|
||||
if blob = find_signed_blob
|
||||
expires_in 5.minutes # service_url defaults to 5 minutes
|
||||
redirect_to blob.service_url(disposition: disposition_param)
|
||||
else
|
||||
head :not_found
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
class ActiveStorage::VariantsController < ActionController::Base
|
||||
def show
|
||||
if blob = find_signed_blob
|
||||
expires_in 5.minutes # service_url defaults to 5 minutes
|
||||
redirect_to ActiveStorage::Variant.new(blob, decoded_variation).processed.service_url(disposition: disposition_param)
|
||||
else
|
||||
head :not_found
|
||||
|
|
15
activestorage/test/controllers/blobs_controller_test.rb
Normal file
15
activestorage/test/controllers/blobs_controller_test.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require "test_helper"
|
||||
require "database/setup"
|
||||
|
||||
class ActiveStorage::BlobsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@blob = create_image_blob filename: "racecar.jpg"
|
||||
end
|
||||
|
||||
test "showing blob utilizes browser caching" do
|
||||
get rails_blob_url(@blob)
|
||||
|
||||
assert_redirected_to(/racecar.jpg/)
|
||||
assert_equal "max-age=300, private", @response.headers["Cache-Control"]
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue