class Puppet::HTTP::Response

Represents the response returned from the server from an HTTP request.

@api abstract @api public

Attributes

url[R]

@return [URI] the response url

Public Class Methods

new(url, code, reason) click to toggle source

Create a response associated with the URL.

@param [URI] url @param [Integer] HTTP status @param [String] HTTP reason

   # File lib/puppet/http/response.rb
14 def initialize(url, code, reason)
15   @url = url
16   @code = code
17   @reason = reason
18 end

Public Instance Methods

[](name) click to toggle source

Get a header case-insensitively.

@param [String] name The header name @return [String] The header value

@api public

   # File lib/puppet/http/response.rb
77 def [](name)
78   raise NotImplementedError
79 end
body() click to toggle source

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.

@return [String] Response body for the request

@api public

   # File lib/puppet/http/response.rb
45 def body
46   raise NotImplementedError
47 end
code() click to toggle source

Return the response code.

@return [Integer] Response code for the request

@api public

   # File lib/puppet/http/response.rb
25 def code
26   @code
27 end
drain() click to toggle source

Ensure the response body is fully read so that the server is not blocked waiting for us to read data from the socket. Also if the caller streamed the response, but didn't read the data, we need a way to drain the socket before adding the connection back to the connection pool, otherwise the unread response data would “leak” into the next HTTP request/response.

@api public

    # File lib/puppet/http/response.rb
 98 def drain
 99   body
100   true
101 end
each_header(&block) click to toggle source

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

@yieldparam [String] header name @yieldparam [String] header value

@api public

   # File lib/puppet/http/response.rb
87 def each_header(&block)
88   raise NotImplementedError
89 end
read_body(&block) click to toggle source

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.

@yield [String] Streams the response body in chunks

@raise [ArgumentError] raise if a block is not given

@api public

   # File lib/puppet/http/response.rb
58 def read_body(&block)
59   raise NotImplementedError
60 end
reason() click to toggle source

Return the response message.

@return [String] Response message for the request

@api public

   # File lib/puppet/http/response.rb
34 def reason
35   @reason
36 end
success?() click to toggle source

Check if the request received a response of success (HTTP 2xx).

@return [Boolean] Returns true if the response indicates success

@api public

   # File lib/puppet/http/response.rb
67 def success?
68   200 <= @code && @code < 300
69 end