Only stream success responses from Cellar

This commit is contained in:
Frederic Merizen 2018-02-15 14:36:25 +01:00
parent 9d34262493
commit 7df20a35cd

View file

@ -12,13 +12,16 @@ module ActiveStorage
end
def download(key)
# TODO: error handling
if block_given?
instrument :streaming_download, key: key do
http_start do |http|
http.request(get_request(key)) do |response|
response.read_body do |chunk|
yield(chunk.force_encoding(Encoding::BINARY))
if response.is_a?(Net::HTTPSuccess)
response.read_body do |chunk|
yield(chunk.force_encoding(Encoding::BINARY))
end
else
# TODO: error handling
end
end
end
@ -29,6 +32,8 @@ module ActiveStorage
response = http.request(get_request(key))
if response.is_a?(Net::HTTPSuccess)
response.body.force_encoding(Encoding::BINARY)
else
# TODO: error handling
end
end
end