Class: Puppet::HTTP::ExternalClient Private
- Defined in:
- lib/puppet/http/external_client.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Adapts an external http_client_class to the HTTP client API. The former is typically registered by puppetserver and only implements a subset of the Puppet::Network::HTTP::Connection methods. As a result, only the ‘get` and `post` methods are supported. Calling `delete`, etc will raise a NotImplementedError.
Instance Attribute Summary
Attributes inherited from Client
Instance Method Summary collapse
-
#close ⇒ void
Close persistent connections in the pool.
- #connect(uri, options: {}, &block) ⇒ Object private
-
#create_session ⇒ Object
private
The following are intentionally not documented.
- #delete(url, headers: {}, params: {}, options: {}) ⇒ Object private
-
#get(url, headers: {}, params: {}, options: {}) {|Puppet::HTTP::Response| ... } ⇒ Puppet::HTTP::Response
Submits a GET HTTP request to the given url.
- #head(url, headers: {}, params: {}, options: {}) ⇒ Object private
-
#initialize(http_client_class) ⇒ ExternalClient
constructor
private
Create an external http client.
-
#post(url, body, headers: {}, params: {}, options: {}) {|Puppet::HTTP::Response| ... } ⇒ Puppet::HTTP::Response
Submits a POST HTTP request to the given url.
- #put(url, headers: {}, params: {}, options: {}) ⇒ Object private
Methods inherited from Client
Constructor Details
#initialize(http_client_class) ⇒ ExternalClient
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create an external http client.
14 15 16 |
# File 'lib/puppet/http/external_client.rb', line 14 def initialize(http_client_class) @http_client_class = http_client_class end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Close persistent connections in the pool.
64 65 66 |
# File 'lib/puppet/http/external_client.rb', line 64 def close # This is a noop as puppetserver doesn't provide a way to close its http client. end |
#connect(uri, options: {}, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/puppet/http/external_client.rb', line 74 def connect(uri, options: {}, &block) raise NotImplementedError end |
#create_session ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The following are intentionally not documented
70 71 72 |
# File 'lib/puppet/http/external_client.rb', line 70 def create_session raise NotImplementedError end |
#delete(url, headers: {}, params: {}, options: {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/puppet/http/external_client.rb', line 86 def delete(url, headers: {}, params: {}, options: {}) raise NotImplementedError end |
#get(url, headers: {}, params: {}, options: {}) {|Puppet::HTTP::Response| ... } ⇒ Puppet::HTTP::Response
Submits a GET HTTP request to the given url
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet/http/external_client.rb', line 20 def get(url, headers: {}, params: {}, options: {}, &block) url = encode_query(url, params) [:use_ssl] = url.scheme == 'https' client = @http_client_class.new(url.host, url.port, ) response = Puppet::HTTP::ResponseNetHTTP.new(url, client.get(url.request_uri, headers, )) if block_given? yield response else response end rescue Puppet::HTTP::HTTPError raise rescue => e raise Puppet::HTTP::HTTPError.new(e., e) end |
#head(url, headers: {}, params: {}, options: {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/puppet/http/external_client.rb', line 78 def head(url, headers: {}, params: {}, options: {}) raise NotImplementedError end |
#post(url, body, headers: {}, params: {}, options: {}) {|Puppet::HTTP::Response| ... } ⇒ Puppet::HTTP::Response
Submits a POST HTTP request to the given url
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/http/external_client.rb', line 41 def post(url, body, headers: {}, params: {}, options: {}, &block) raise ArgumentError, "'post' requires a string 'body' argument" unless body.is_a?(String) url = encode_query(url, params) [:use_ssl] = url.scheme == 'https' client = @http_client_class.new(url.host, url.port, ) response = Puppet::HTTP::ResponseNetHTTP.new(url, client.post(url.request_uri, body, headers, )) if block_given? yield response else response end rescue Puppet::HTTP::HTTPError, ArgumentError raise rescue => e raise Puppet::HTTP::HTTPError.new(e., e) end |
#put(url, headers: {}, params: {}, options: {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/puppet/http/external_client.rb', line 82 def put(url, headers: {}, params: {}, options: {}) raise NotImplementedError end |