shrinerb / shrine

File Attachment toolkit for Ruby applications
https://shrinerb.com
MIT License
3.18k stars 275 forks source link

add custom etag option to rack_response plugin #704

Open prem-prakash opened 2 months ago

prem-prakash commented 2 months ago

The rack_response plugin ETAG response header is generated based on attributes that can remain the same even if the file content has been changed.

        # Value for the "ETag" header.
        def etag
          digest = Digest::SHA256.hexdigest("#{file.shrine_class}-#{file.storage_key}-#{file.id}")

          %(W/"#{digest.byteslice(0, 32)}")
        end

This may result in unwanted response caching.

janko commented 2 months ago

Looks good to me, thanks 👍🏻 I would just rename the keyword argument to :etag, as it communicates better that we're overriding the ETag. Also, would you mind updating the documentation?