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