Merge pull request #43637 from alxjrvs/blob-representation-disposition

Fix Rails 7 Regression - ActiveStorage Content Disposition
This commit is contained in:
Rafael Mendonça França 2021-12-06 17:39:14 -05:00 committed by GitHub
commit 47fc79ca2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View File

@ -17,7 +17,7 @@ class ActiveStorage::Blobs::ProxyController < ActiveStorage::BaseController
response.headers["Accept-Ranges"] = "bytes"
response.headers["Content-Length"] = @blob.byte_size.to_s
send_blob_stream @blob
send_blob_stream @blob, disposition: params[:disposition]
end
end
end

View File

@ -9,7 +9,7 @@
class ActiveStorage::Representations::ProxyController < ActiveStorage::Representations::BaseController
def show
http_cache_forever public: true do
send_blob_stream @representation.image
send_blob_stream @representation.image, disposition: params[:disposition]
end
end
end

View File

@ -21,11 +21,17 @@ class ActiveStorage::Blobs::ProxyControllerTest < ActionDispatch::IntegrationTes
assert_equal "application/octet-stream", response.headers["Content-Type"]
end
test "forcing Content-Disposition to attachment" do
test "forcing Content-Disposition to attachment based on type" do
get rails_storage_proxy_url(create_blob(content_type: "application/zip"))
assert_match(/^attachment; /, response.headers["Content-Disposition"])
end
test "caller can change disposition to attachment" do
url = rails_storage_proxy_url(create_blob(content_type: "image/jpeg"), disposition: :attachment)
get url
assert_match(/^attachment; /, response.headers["Content-Disposition"])
end
test "signed ID within expiration date" do
get rails_storage_proxy_url(create_file_blob(filename: "racecar.jpg"), expires_in: 1.minute)
assert_response :success

View File

@ -8,6 +8,22 @@ class ActiveStorage::Representations::ProxyControllerWithVariantsTest < ActionDi
@blob = create_file_blob filename: "racecar.jpg"
end
test "showing variant attachment" do
get rails_blob_representation_proxy_url(
disposition: :attachment,
filename: @blob.filename,
signed_blob_id: @blob.signed_id,
variation_key: ActiveStorage::Variation.encode(resize_to_limit: [100, 100]))
assert_response :ok
assert_match(/^attachment/, response.headers["Content-Disposition"])
image = read_image(@blob.variant(resize_to_limit: [100, 100]))
assert_equal 100, image.width
assert_equal 67, image.height
end
test "showing variant inline" do
get rails_blob_representation_proxy_url(
filename: @blob.filename,