CleverCloud Cellar Compatible range query

This commit is contained in:
Frederic Merizen 2018-02-15 17:41:44 +01:00
parent d02ae00c0e
commit 18db0ceae9

View file

@ -1,9 +1,12 @@
ActiveStorage::Identification.class_eval do
def apply
# Monkey patch ActiveStorage to trust the user-submitted content type rather than determining
# it from the file contents, because Cellar does not seem to support the Range header
# Monkey patch ActiveStorage to make Range query compatible with CleverCloud Cellar
#
# FIXME : remove when better fix is available
blob.update!(content_type: declared_content_type, identified: true) unless blob.identified?
ActiveStorage::Identification.class_eval do
private
def identifiable_chunk
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |client|
client.get(uri, "Range" => "bytes=0-4096").body
end
end
end