Module: Puppet::Network::HTTP::Compression::Active

Defined in:
lib/vendor/puppet/network/http/compression.rb

Defined Under Namespace

Classes: ZlibAdapter

Instance Method Summary collapse

Instance Method Details

#add_accept_encoding(headers = {}) ⇒ Object



48
49
50
51
# File 'lib/vendor/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| ... } ⇒ Object

Yields:

  • (uncompressor)

Raises:

  • (Net::HTTPError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vendor/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) ⇒ Object

return an uncompressed body if the response has been compressed



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vendor/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