Skip to content

Commit

Permalink
add custom etag option to rack_response plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
prem-prakash committed Sep 5, 2024
1 parent 1ce6da4 commit 3ecd145
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/shrine/plugins/rack_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def rack_status(range: nil, **)
# "Content-Disposition" headers, whose values are extracted from
# metadata. Also returns the correct "Content-Range" header on ranged
# requests.
def rack_headers(filename: nil, type: nil, disposition: "inline", range: false)
def rack_headers(filename: nil, type: nil, disposition: "inline", range: false, custom_etag: nil)
{
"Content-Length" => content_length(range),
"Content-Type" => content_type(type),
"Content-Disposition" => content_disposition(disposition, filename),
"Content-Range" => content_range(range),
"Accept-Ranges" => accept_ranges(range),
"ETag" => etag,
"ETag" => custom_etag || etag,
}.compact
end

Expand Down
7 changes: 7 additions & 0 deletions test/plugin/rack_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@
assert_equal etags, etags.uniq
end

it "allows custom ETAG value" do
uploaded_file = @uploader.upload(fakeio)
response = uploaded_file.to_rack_response(custom_etag: "VeryCustomETAG")
assert_instance_of String, response[1]["ETag"]
assert_match "VeryCustomETAG", response[1]["ETag"]
end

it "implements #to_path on the body for filesystem storage" do
uploaded_file = @uploader.upload(fakeio)
response = uploaded_file.to_rack_response
Expand Down

0 comments on commit 3ecd145

Please sign in to comment.