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.
16 17 18 19 20 |
# File 'lib/puppet/http/response.rb', line 16 def initialize(url, code, reason) @url = url @code = code @reason = reason end |
Instance Attribute Details
#url ⇒ URI (readonly)
Returns the response url.
9 10 11 |
# File 'lib/puppet/http/response.rb', line 9 def url @url end |
Instance Method Details
#[](name) ⇒ String
Get a header case-insensitively.
79 80 81 |
# File 'lib/puppet/http/response.rb', line 79 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.
47 48 49 |
# File 'lib/puppet/http/response.rb', line 47 def body raise NotImplementedError end |
#code ⇒ Integer
Return the response code.
27 28 29 |
# File 'lib/puppet/http/response.rb', line 27 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.
100 101 102 103 |
# File 'lib/puppet/http/response.rb', line 100 def drain body true end |
#each_header {|header, header| ... } ⇒ Object
Yield each header name and value. Returns an enumerator if no block is given.
89 90 91 |
# File 'lib/puppet/http/response.rb', line 89 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.
60 61 62 |
# File 'lib/puppet/http/response.rb', line 60 def read_body(&block) raise NotImplementedError end |
#reason ⇒ String
Return the response message.
36 37 38 |
# File 'lib/puppet/http/response.rb', line 36 def reason @reason end |
#success? ⇒ Boolean
Check if the request received a response of success (HTTP 2xx).
69 70 71 |
# File 'lib/puppet/http/response.rb', line 69 def success? 200 <= @code && @code < 300 end |