Sha256: 45682e1acedf65a9fd93ab494b8acf41928e4a126d2fe454c1b28bf8c55d40ee

Contents?: true

Size: 915 Bytes

Versions: 20

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true
module Puppet::HTTP::ResponseConverter
  module_function

  # Borrowed from puppetserver, see https://github.com/puppetlabs/puppetserver/commit/a1ebeaaa5af590003ccd23c89f808ba4f0c89609
  def to_ruby_response(response)
    str_code = response.code.to_s

    # Copied from Net::HTTPResponse because it is private there.
    clazz = Net::HTTPResponse::CODE_TO_OBJ[str_code] or
      Net::HTTPResponse::CODE_CLASS_TO_OBJ[str_code[0,1]] or
      Net::HTTPUnknownResponse
    result = clazz.new(nil, str_code, nil)
    result.body = response.body
    # This is nasty, nasty.  But apparently there is no way to create
    # an instance of Net::HttpResponse from outside of the library and have
    # the body be readable, unless you do stupid things like this.
    result.instance_variable_set(:@read, true)
    response.each_header do |k,v|
      result[k] = v
    end
    result
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.3.0 lib/puppet/http/response_converter.rb
puppet-8.3.0-x86-mingw32 lib/puppet/http/response_converter.rb
puppet-8.3.0-x64-mingw32 lib/puppet/http/response_converter.rb
puppet-8.3.0-universal-darwin lib/puppet/http/response_converter.rb
puppet-8.3.1 lib/puppet/http/response_converter.rb
puppet-8.3.1-x86-mingw32 lib/puppet/http/response_converter.rb
puppet-8.3.1-x64-mingw32 lib/puppet/http/response_converter.rb
puppet-8.3.1-universal-darwin lib/puppet/http/response_converter.rb
puppet-8.2.0 lib/puppet/http/response_converter.rb
puppet-8.2.0-x86-mingw32 lib/puppet/http/response_converter.rb
puppet-8.2.0-x64-mingw32 lib/puppet/http/response_converter.rb
puppet-8.2.0-universal-darwin lib/puppet/http/response_converter.rb
puppet-8.1.0 lib/puppet/http/response_converter.rb
puppet-8.1.0-x86-mingw32 lib/puppet/http/response_converter.rb
puppet-8.1.0-x64-mingw32 lib/puppet/http/response_converter.rb
puppet-8.1.0-universal-darwin lib/puppet/http/response_converter.rb
puppet-8.0.1 lib/puppet/http/response_converter.rb
puppet-8.0.1-x86-mingw32 lib/puppet/http/response_converter.rb
puppet-8.0.1-x64-mingw32 lib/puppet/http/response_converter.rb
puppet-8.0.1-universal-darwin lib/puppet/http/response_converter.rb