From 18db0ceae9b43b3c953053040ba8b7bab8a71a88 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 15 Feb 2018 17:41:44 +0100 Subject: [PATCH] CleverCloud Cellar Compatible range query --- config/initializers/monkey_patches.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/config/initializers/monkey_patches.rb b/config/initializers/monkey_patches.rb index 5c82ece93..ffe0a92ba 100644 --- a/config/initializers/monkey_patches.rb +++ b/config/initializers/monkey_patches.rb @@ -1,9 +1,12 @@ +# Monkey patch ActiveStorage to make Range query compatible with CleverCloud Cellar +# +# FIXME : remove when better fix is available 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 - # - # FIXME : remove when better fix is available - blob.update!(content_type: declared_content_type, identified: true) unless blob.identified? + 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