lib/ridley/connection.rb in ridley-0.12.2 vs lib/ridley/connection.rb in ridley-0.12.3
- old
+ new
@@ -1,8 +1,9 @@
require 'open-uri'
require 'retryable'
require 'tempfile'
+require 'zlib'
module Ridley
# @author Jamie Winsor <reset@riotgames.com>
class Connection < Faraday::Connection
include Celluloid
@@ -46,10 +47,11 @@
@retries = options[:retries]
@retry_interval = options[:retry_interval]
options[:builder] = Faraday::Builder.new do |b|
b.response :json
+ b.response :gzip
b.request :retry,
max: @retries,
interval: @retry_interval,
exceptions: [
Ridley::Errors::HTTP5XXError,
@@ -139,10 +141,17 @@
local.binmode
defer {
retryable(tries: retries, on: OpenURI::HTTPError, sleep: retry_interval) do
open(target, 'rb', headers) do |remote|
- local.write(remote.read)
+ body = remote.read
+ case remote.content_encoding
+ when ['gzip']
+ body = Zlib::GzipReader.new(StringIO.new(body), encoding: 'ASCII-8BIT').read
+ when ['deflate']
+ body = Zlib::Inflate.inflate(body)
+ end
+ local.write(body)
end
end
local.flush
}