Class: Puppet::HTTP::Response
Overview
Represents the response returned from the server from an HTTP request.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#url ⇒ URI
readonly
The response url.
Instance Method Summary collapse
-
#[](name) ⇒ String
Get a header case-insensitively.
-
#body ⇒ String
Returns the entire response body.
-
#code ⇒ Integer
Return the response code.
-
#drain ⇒ Object
Ensure the response body is fully read so that the server is not blocked waiting for us to read data from the socket.
-
#each_header {|header, header| ... } ⇒ Object
Yield each header name and value.
-
#initialize(url, code, reason) ⇒ Response
constructor
Create a response associated with the URL.
-
#read_body {|String| ... } ⇒ Object
Streams the response body to the caller in chunks.
-
#reason ⇒ String
Return the response message.
-
#success? ⇒ Boolean
Check if the request received a response of success (HTTP 2xx).
Constructor Details
#initialize(url, code, reason) ⇒ Response
Create a response associated with the URL.
14 15 16 17 18 |
# File 'lib/puppet/http/response.rb', line 14 def initialize(url, code, reason) @url = url @code = code @reason = reason end |
Instance Attribute Details
#url ⇒ URI (readonly)
Returns the response url.
7 8 9 |
# File 'lib/puppet/http/response.rb', line 7 def url @url end |
Instance Method Details
#[](name) ⇒ String
Get a header case-insensitively.
77 78 79 |
# File 'lib/puppet/http/response.rb', line 77 def [](name) raise NotImplementedError end |
#body ⇒ String
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.
45 46 47 |
# File 'lib/puppet/http/response.rb', line 45 def body raise NotImplementedError end |
#code ⇒ Integer
Return the response code.
25 26 27 |
# File 'lib/puppet/http/response.rb', line 25 def code @code end |
#drain ⇒ Object
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.
98 99 100 101 |
# File 'lib/puppet/http/response.rb', line 98 def drain body true end |
#each_header {|header, header| ... } ⇒ Object
Yield each header name and value. Returns an enumerator if no block is given.
87 88 89 |
# File 'lib/puppet/http/response.rb', line 87 def each_header(&block) raise NotImplementedError end |
#read_body {|String| ... } ⇒ Object
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.
58 59 60 |
# File 'lib/puppet/http/response.rb', line 58 def read_body(&block) raise NotImplementedError end |
#reason ⇒ String
Return the response message.
34 35 36 |
# File 'lib/puppet/http/response.rb', line 34 def reason @reason end |
#success? ⇒ Boolean
Check if the request received a response of success (HTTP 2xx).
67 68 69 |
# File 'lib/puppet/http/response.rb', line 67 def success? 200 <= @code && @code < 300 end |