module Puppet::HTTP::ResponseConverter

Public Instance Methods

to_ruby_response(response) click to toggle source

Borrowed from puppetserver, see github.com/puppetlabs/puppetserver/commit/a1ebeaaa5af590003ccd23c89f808ba4f0c89609

   # File lib/puppet/http/response_converter.rb
 5 def to_ruby_response(response)
 6   str_code = response.code.to_s
 7 
 8   # Copied from Net::HTTPResponse because it is private there.
 9   clazz = Net::HTTPResponse::CODE_TO_OBJ[str_code] or
10     Net::HTTPResponse::CODE_CLASS_TO_OBJ[str_code[0,1]] or
11     Net::HTTPUnknownResponse
12   result = clazz.new(nil, str_code, nil)
13   result.body = response.body
14   # This is nasty, nasty.  But apparently there is no way to create
15   # an instance of Net::HttpResponse from outside of the library and have
16   # the body be readable, unless you do stupid things like this.
17   result.instance_variable_set(:@read, true)
18   response.each_header do |k,v|
19     result[k] = v
20   end
21   result
22 end