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.
10 11 12 13 14 |
# File 'lib/puppet/http/response_net_http.rb', line 10 def initialize(url, nethttp) super(url, nethttp.code.to_i, nethttp.) @nethttp = nethttp end |
Instance Method Details
#[](name) ⇒ String
Get a header case-insensitively.
34 35 36 |
# File 'lib/puppet/http/response_net_http.rb', line 34 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.
17 18 19 |
# File 'lib/puppet/http/response_net_http.rb', line 17 def body @nethttp.body end |
#each_header {|header, header| ... } ⇒ Object
Yield each header name and value. Returns an enumerator if no block is given.
39 40 41 |
# File 'lib/puppet/http/response_net_http.rb', line 39 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.
22 23 24 25 26 |
# File 'lib/puppet/http/response_net_http.rb', line 22 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).
29 30 31 |
# File 'lib/puppet/http/response_net_http.rb', line 29 def success? @nethttp.is_a?(Net::HTTPSuccess) end |