Skip to content

Commit

Permalink
fix the way of Zlib::Inflate in ruby-1.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rockuw committed Jan 29, 2016
1 parent b0fa2ae commit f0220a3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/aliyun/oss/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,24 @@ def handle_response(r, &block)
elsif encoding == 'deflate'
begin
stream = Zlib::Inflate.new
r.read_body { |chunk| stream << chunk }
stream.finish { |chunk| yield chunk }
# 1.9.x doesn't support streaming inflate
if RUBY_VERSION < '2.0.0'
yield stream.inflate(r.read_body)
else
r.read_body { |chunk| stream << chunk }
stream.finish { |chunk| yield chunk }
end
rescue Zlib::DataError
# No luck with Zlib decompression. Let's try with raw deflate,
# like some broken web servers do.
stream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
r.read_body { |chunk| stream << chunk }
stream.finish { |chunk| yield chunk }
# 1.9.x doesn't support streaming inflate
if RUBY_VERSION < '2.0.0'
yield stream.inflate(r.read_body)
else
r.read_body { |chunk| stream << chunk }
stream.finish { |chunk| yield chunk }
end
end
else
r.read_body { |chunk| yield chunk }
Expand Down

0 comments on commit f0220a3

Please sign in to comment.