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

Parameters:

  • nethttp (Net::HTTP)

    the request response

  • url (URI)

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.

Returns:

  • (Net::HTTP)

    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.

Returns:

  • (URI)

    the response uri


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

def url
  @url
end

Instance Method Details

#[](name) ⇒ 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.


92
93
94
# File 'lib/puppet/http/response.rb', line 92

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.

Returns:

  • (String)

    Response body for the request


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

Returns:

  • (Integer)

    Response code for the request


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.


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

def drain
  body
  true
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

Returns:

  • (String)

    Response message for the request


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

Returns:

  • (Boolean)

    Returns true if the response indicates success


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

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