Checks for a supported Content-Encoding header and yields an Inflate
wrapper for this response’s socket when zlib is present. If the
Content-Encoding is unsupported or zlib is missing the plain socket is
yielded.
If a Content-Range header is
present a plain socket is yielded as the bytes in the range may not be a
complete deflate block.
# File lib/net/http/response.rb, line 248
def inflater # :nodoc:
return yield @socket unless Net::HTTP::HAVE_ZLIB
return yield @socket unless @decode_content
return yield @socket if self['content-range']
v = self['content-encoding']
case v && v.downcase
when 'deflate', 'gzip', 'x-gzip' then
self.delete 'content-encoding'
inflate_body_io = Inflater.new(@socket)
begin
yield inflate_body_io
ensure
orig_err = $!
begin
inflate_body_io.finish
rescue => err
raise orig_err || err
end
end
when 'none', 'identity' then
self.delete 'content-encoding'
yield @socket
else
yield @socket
end
end