Class: Puppet::HTTP::Client Private
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.
The client contains a pool of persistent HTTP connections and creates HTTP sessions.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#pool ⇒ Puppet::Network::HTTP::Pool
readonly
private
The pool instance associated with this client.
Instance Method Summary collapse
-
#close ⇒ Object
private
Close persistent connections in the pool.
-
#connect(uri, options: {}) {|Net::HTTP| ... } ⇒ Object
private
Open a connection to the given URI.
-
#create_session ⇒ Puppet::HTTP::Session
private
Create a new HTTP session.
-
#delete(url, headers: {}, params: {}, options: {}) ⇒ String
private
Submits a DELETE HTTP request to the given url.
-
#get(url, headers: {}, params: {}, options: {}) {|Puppet::HTTP::Response| ... } ⇒ String
private
Submits a GET HTTP request to the given url.
-
#head(url, headers: {}, params: {}, options: {}) ⇒ String
private
Submits a HEAD HTTP request to the given url.
-
#initialize(pool: Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout]), ssl_context: nil, system_ssl_context: nil, redirect_limit: 10, retry_limit: 100) ⇒ Client
constructor
private
Create a new http client instance.
-
#post(url, body, headers: {}, params: {}, options: {}, &block) ⇒ String
private
Submits a POST HTTP request to the given url.
-
#put(url, body, headers: {}, params: {}, options: {}) ⇒ String
private
Submits a PUT HTTP request to the given url.
Constructor Details
#initialize(pool: Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout]), ssl_context: nil, system_ssl_context: nil, redirect_limit: 10, retry_limit: 100) ⇒ Client
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 a new http client instance. The client contains a pool of persistent HTTP connections and creates HTTP sessions.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/http/client.rb', line 31 def initialize(pool: Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout]), ssl_context: nil, system_ssl_context: nil, redirect_limit: 10, retry_limit: 100) @pool = pool @default_headers = { 'X-Puppet-Version' => Puppet.version, 'User-Agent' => Puppet[:http_user_agent], }.freeze @default_ssl_context = ssl_context @default_system_ssl_context = system_ssl_context @default_redirect_limit = redirect_limit @retry_after_handler = Puppet::HTTP::RetryAfterHandler.new(retry_limit, Puppet[:runinterval]) end |
Instance Attribute Details
#pool ⇒ Puppet::Network::HTTP::Pool (readonly)
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.
Returns the pool instance associated with this client.
12 13 14 |
# File 'lib/puppet/http/client.rb', line 12 def pool @pool end |
Instance Method Details
#close ⇒ 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.
Close persistent connections in the pool
273 274 275 |
# File 'lib/puppet/http/client.rb', line 273 def close @pool.close end |
#connect(uri, options: {}) {|Net::HTTP| ... } ⇒ 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.
Open a connection to the given URI
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/puppet/http/client.rb', line 70 def connect(uri, options: {}, &block) start = Time.now verifier = nil connected = false site = Puppet::Network::HTTP::Site.from_uri(uri) if site.use_ssl? ssl_context = .fetch(:ssl_context, nil) include_system_store = .fetch(:include_system_store, false) ctx = resolve_ssl_context(ssl_context, include_system_store) verifier = Puppet::SSL::Verifier.new(site.host, ctx) end @pool.with_connection(site, verifier) do |http| connected = true if block_given? yield http end end rescue Net::OpenTimeout => e raise_error(_("Request to %{uri} timed out connect operation after %{elapsed} seconds") % {uri: uri, elapsed: elapsed(start)}, e, connected) rescue Net::ReadTimeout => e raise_error(_("Request to %{uri} timed out read operation after %{elapsed} seconds") % {uri: uri, elapsed: elapsed(start)}, e, connected) rescue EOFError => e raise_error(_("Request to %{uri} interrupted after %{elapsed} seconds") % {uri: uri, elapsed: elapsed(start)}, e, connected) rescue Puppet::SSL::SSLError raise rescue Puppet::HTTP::HTTPError raise rescue => e raise_error(_("Request to %{uri} failed after %{elapsed} seconds: %{message}") % {uri: uri, elapsed: elapsed(start), message: e.}, e, connected) end |
#create_session ⇒ Puppet::HTTP::Session
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 a new HTTP session. A session is the object through which services may be connected to and accessed.
51 52 53 |
# File 'lib/puppet/http/client.rb', line 51 def create_session Puppet::HTTP::Session.new(self, build_resolvers) end |
#delete(url, headers: {}, params: {}, options: {}) ⇒ String
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.
Submits a DELETE HTTP request to the given url
258 259 260 261 262 263 264 265 266 |
# File 'lib/puppet/http/client.rb', line 258 def delete(url, headers: {}, params: {}, options: {}) url = encode_query(url, params) request = Net::HTTP::Delete.new(url, @default_headers.merge(headers)) execute_streaming(request, options: ) do |response| response.body end end |
#get(url, headers: {}, params: {}, options: {}) {|Puppet::HTTP::Response| ... } ⇒ String
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.
Submits a GET HTTP request to the given url
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppet/http/client.rb', line 124 def get(url, headers: {}, params: {}, options: {}, &block) url = encode_query(url, params) request = Net::HTTP::Get.new(url, @default_headers.merge(headers)) execute_streaming(request, options: ) do |response| if block_given? yield response else response.body end end end |
#head(url, headers: {}, params: {}, options: {}) ⇒ String
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.
Submits a HEAD HTTP request to the given url
156 157 158 159 160 161 162 163 164 |
# File 'lib/puppet/http/client.rb', line 156 def head(url, headers: {}, params: {}, options: {}) url = encode_query(url, params) request = Net::HTTP::Head.new(url, @default_headers.merge(headers)) execute_streaming(request, options: ) do |response| response.body end end |
#post(url, body, headers: {}, params: {}, options: {}, &block) ⇒ String
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.
Submits a POST HTTP request to the given url
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/puppet/http/client.rb', line 221 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) request = Net::HTTP::Post.new(url, @default_headers.merge(headers)) request.body = body request.content_length = body.bytesize raise ArgumentError, "'post' requires a 'content-type' header" unless request['Content-Type'] execute_streaming(request, options: ) do |response| if block_given? yield response else response.body end end end |
#put(url, body, headers: {}, params: {}, options: {}) ⇒ String
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.
Submits a PUT HTTP request to the given url
186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/puppet/http/client.rb', line 186 def put(url, body, headers: {}, params: {}, options: {}) raise ArgumentError, "'put' requires a string 'body' argument" unless body.is_a?(String) url = encode_query(url, params) request = Net::HTTP::Put.new(url, @default_headers.merge(headers)) request.body = body request.content_length = body.bytesize raise ArgumentError, "'put' requires a 'content-type' header" unless request['Content-Type'] execute_streaming(request, options: ) do |response| response.body end end |