1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

[ActiveStorage] Return "Range Not Satisfiable" return code for partial downloads with incorrect range

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
This commit is contained in:
fatkodima 2022-08-30 21:48:26 +03:00
parent 02f3b999a0
commit bc2aad4ae4
2 changed files with 9 additions and 0 deletions

View file

@ -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 @@ module ActiveStorage::FileServer # :nodoc:
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

View file

@ -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