class Puppet::HTTP::Response
Represents the response returned from the server from an HTTP request.
@api abstract @api public
Attributes
@return [URI] the response url
Public Class Methods
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
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
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
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
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
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
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
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
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