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 15 def initialize(url, code, reason) 16 @url = url 17 @code = code 18 @reason = reason 19 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 78 def [](name) 79 raise NotImplementedError 80 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 46 def body 47 raise NotImplementedError 48 end
Return the response code.
@return [Integer] Response code for the request
@api public
# File lib/puppet/http/response.rb 26 def code 27 @code 28 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 99 def drain 100 body 101 true 102 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 88 def each_header(&block) 89 raise NotImplementedError 90 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 59 def read_body(&block) 60 raise NotImplementedError 61 end
Return the response message.
@return [String] Response message for the request
@api public
# File lib/puppet/http/response.rb 35 def reason 36 @reason 37 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 68 def success? 69 200 <= @code && @code < 300 70 end