Merge pull request #45911 from fatkodima/invalid-range-disk-controller

[ActiveStorage] Return "Range Not Satisfiable" return code for partial downloads with incorrect range
This commit is contained in:
Jean Boussier 2022-09-02 08:29:52 +02:00 committed by GitHub
commit d96612d3ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

@ -1,5 +1,7 @@
# frozen_string_literal: true
require "active_support/core_ext/hash/except"
module ActiveStorage::FileServer # :nodoc:
private
def serve_file(path, content_type:, disposition:)
@ -11,6 +13,7 @@ def serve_file(path, content_type:, disposition:)
response.headers[name] = value
end
response.headers.except!("X-Cascade", "x-cascade") if status == 416
response.headers["Content-Type"] = content_type || DEFAULT_SEND_FILE_TYPE
response.headers["Content-Disposition"] = disposition || DEFAULT_SEND_FILE_DISPOSITION
end

@ -32,6 +32,12 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest
assert_equal " worl", response.body
end
test "showing blob with invalid range" do
blob = create_blob
get blob.url, headers: { "Range" => "bytes=1000-1000" }
assert_response :range_not_satisfiable
end
test "showing blob that does not exist" do
blob = create_blob
blob.delete