Class: Puppet::HTTP::Response Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/http/response.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents the response returned from the server from an HTTP request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nethttp, url) ⇒ Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object to represent the response returned from an HTTP request



23
24
25
26
# File 'lib/puppet/http/response.rb', line 23

def initialize(nethttp, url)
  @nethttp = nethttp
  @url = url
end

Instance Attribute Details

#nethttpNet::HTTP (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the Net::HTTP response.



9
10
11
# File 'lib/puppet/http/response.rb', line 9

def nethttp
  @nethttp
end

#urlURI (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the response uri.



13
14
15
# File 'lib/puppet/http/response.rb', line 13

def url
  @url
end

Instance Method Details

#[](name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a header case-insensitively.



97
98
99
# File 'lib/puppet/http/response.rb', line 97

def [](name)
  @nethttp[name]
end

#bodyString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the entire response body. Can be used instead of Puppet::HTTP::Response.read_body, but both methods cannot be used for the same response.



59
60
61
# File 'lib/puppet/http/response.rb', line 59

def body
  @nethttp.body
end

#codeInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract the response code



35
36
37
# File 'lib/puppet/http/response.rb', line 35

def code
  @nethttp.code.to_i
end

#drainObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Drain the response body.



116
117
118
119
# File 'lib/puppet/http/response.rb', line 116

def drain
  body
  true
end

#each_header {|header, header| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yield each header name and value. Returns an enumerator if no block is given.

Yield Parameters:

  • header (String)

    name

  • header (String)

    value



108
109
110
# File 'lib/puppet/http/response.rb', line 108

def each_header(&block)
  @nethttp.each_header(&block)
end

#read_body {|String| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Streams the response body to the caller in chunks. Can be used instead of Puppet::HTTP::Response.body, but both methods cannot be used for the same response.

Yields:

  • (String)

    Streams the response body in chunks

Raises:

  • (ArgumentError)

    raise if a block is not given



74
75
76
77
78
# File 'lib/puppet/http/response.rb', line 74

def read_body(&block)
  raise ArgumentError, "A block is required" unless block_given?

  @nethttp.read_body(&block)
end

#reasonString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract the response message



46
47
48
# File 'lib/puppet/http/response.rb', line 46

def reason
  @nethttp.message
end

#success?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the request received a response of success



87
88
89
# File 'lib/puppet/http/response.rb', line 87

def success?
  @nethttp.is_a?(Net::HTTPSuccess)
end