Class: Puppet::HTTP::ResponseNetHTTP
- Defined in:
- lib/puppet/http/response_net_http.rb
Overview
Adapts Net::HTTPResponse to Puppet::HTTP::Response
Instance Attribute Summary
Attributes inherited from Response
Instance Method Summary collapse
-
#[](name) ⇒ String
Get a header case-insensitively.
-
#body ⇒ String
Returns the entire response body.
-
#each_header {|header, header| ... } ⇒ Object
Yield each header name and value.
-
#initialize(url, nethttp) ⇒ ResponseNetHTTP
constructor
Create a response associated with the URL.
-
#read_body {|String| ... } ⇒ Object
Streams the response body to the caller in chunks.
-
#success? ⇒ Boolean
Check if the request received a response of success (HTTP 2xx).
Methods inherited from Response
Constructor Details
#initialize(url, nethttp) ⇒ ResponseNetHTTP
Create a response associated with the URL.
11 12 13 14 15 |
# File 'lib/puppet/http/response_net_http.rb', line 11 def initialize(url, nethttp) super(url, nethttp.code.to_i, nethttp.) @nethttp = nethttp end |
Instance Method Details
#[](name) ⇒ String
Get a header case-insensitively.
35 36 37 |
# File 'lib/puppet/http/response_net_http.rb', line 35 def [](name) @nethttp[name] 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.
18 19 20 |
# File 'lib/puppet/http/response_net_http.rb', line 18 def body @nethttp.body end |
#each_header {|header, header| ... } ⇒ Object
Yield each header name and value. Returns an enumerator if no block is given.
40 41 42 |
# File 'lib/puppet/http/response_net_http.rb', line 40 def each_header(&block) @nethttp.each_header(&block) 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.
23 24 25 26 27 |
# File 'lib/puppet/http/response_net_http.rb', line 23 def read_body(&block) raise ArgumentError, "A block is required" unless block_given? @nethttp.read_body(&block) end |
#success? ⇒ Boolean
Check if the request received a response of success (HTTP 2xx).
30 31 32 |
# File 'lib/puppet/http/response_net_http.rb', line 30 def success? @nethttp.is_a?(Net::HTTPSuccess) end |