aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorAnton Khamets <colorfulfool@gmail.com>2017-08-11 20:18:12 +0300
committerRafael França <rafaelmfranca@gmail.com>2017-08-11 13:18:12 -0400
commite25466b142c067ad44130d93fa864f5ffa9643bb (patch)
treeacd4a00126e8b831123db68ab208c1cc05b4e1f7 /activestorage
parentde80aa641290a03c023d00d2ffca368026335fe4 (diff)
downloadrails-e25466b142c067ad44130d93fa864f5ffa9643bb.tar.gz
rails-e25466b142c067ad44130d93fa864f5ffa9643bb.tar.bz2
rails-e25466b142c067ad44130d93fa864f5ffa9643bb.zip
Enable browser caching for blobs and variants (#30196)
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/app/controllers/active_storage/blobs_controller.rb1
-rw-r--r--activestorage/app/controllers/active_storage/variants_controller.rb1
-rw-r--r--activestorage/test/controllers/blobs_controller_test.rb15
3 files changed, 17 insertions, 0 deletions
diff --git a/activestorage/app/controllers/active_storage/blobs_controller.rb b/activestorage/app/controllers/active_storage/blobs_controller.rb
index 05af29f8b2..cff88bd488 100644
--- a/activestorage/app/controllers/active_storage/blobs_controller.rb
+++ b/activestorage/app/controllers/active_storage/blobs_controller.rb
@@ -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
diff --git a/activestorage/app/controllers/active_storage/variants_controller.rb b/activestorage/app/controllers/active_storage/variants_controller.rb
index 994c57aafd..b72b0ff7f5 100644
--- a/activestorage/app/controllers/active_storage/variants_controller.rb
+++ b/activestorage/app/controllers/active_storage/variants_controller.rb
@@ -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
diff --git a/activestorage/test/controllers/blobs_controller_test.rb b/activestorage/test/controllers/blobs_controller_test.rb
new file mode 100644
index 0000000000..5ec353889c
--- /dev/null
+++ b/activestorage/test/controllers/blobs_controller_test.rb
@@ -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