module Puppet::Network::HTTP::Compression::Active

Public Instance Methods

add_accept_encoding(headers={}) click to toggle source
# File lib/puppet/network/http/compression.rb, line 48
def add_accept_encoding(headers={})
  headers['accept-encoding'] = 'gzip; q=1.0, deflate; q=1.0; identity' if Puppet.settings[:http_compression]
  headers
end
uncompress(response) { |uncompressor| ... } click to toggle source
# File lib/puppet/network/http/compression.rb, line 31
def uncompress(response)
  raise Net::HTTPError.new("No block passed") unless block_given?

  case response['content-encoding']
  when 'gzip','deflate'
    uncompressor = ZlibAdapter.new
  when nil, 'identity'
    uncompressor = IdentityAdapter.new
  else
    raise Net::HTTPError.new("Unknown content encoding - #{response['content-encoding']}", response)
  end

  yield uncompressor

  uncompressor.close
end
uncompress_body(response) click to toggle source

return an uncompressed body if the response has been compressed

# File lib/puppet/network/http/compression.rb, line 18
def uncompress_body(response)
  case response['content-encoding']
  when 'gzip'
    return Zlib::GzipReader.new(StringIO.new(response.body)).read
  when 'deflate'
    return Zlib::Inflate.new.inflate(response.body)
  when nil, 'identity'
    return response.body
  else
    raise Net::HTTPError.new("Unknown content encoding - #{response['content-encoding']}", response)
  end
end