Class: Puppet::Network::HTTP::ConnectionAdapter

Inherits:
Connection show all
Defined in:
lib/puppet/network/http/connection_adapter.rb

Constant Summary

Constants inherited from Connection

Puppet::Network::HTTP::Connection::OPTION_DEFAULTS

Instance Method Summary collapse

Methods inherited from Connection

#address, #port, #request, #use_ssl?, #verifier

Constructor Details

#initialize(host, port, options = {}) ⇒ ConnectionAdapter

Returns a new instance of ConnectionAdapter.



2
3
4
5
6
# File 'lib/puppet/network/http/connection_adapter.rb', line 2

def initialize(host, port, options = {})
  super(host, port, options)

  @client = Puppet.runtime[:http]
end

Instance Method Details

#delete(path, headers = {'Depth' => 'Infinity'}, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/puppet/network/http/connection_adapter.rb', line 43

def delete(path, headers = {'Depth' => 'Infinity'}, options = {})
  headers ||= {}
  options[:ssl_context] ||= resolve_ssl_context
  options[:redirect_limit] ||= @redirect_limit

  with_error_handling do
    resp = @client.delete(to_url(path), headers: headers, options: options)
    resp.nethttp
  end
end

#get(path, headers = {}, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/puppet/network/http/connection_adapter.rb', line 8

def get(path, headers = {}, options = {})
  headers ||= {}
  options[:ssl_context] ||= resolve_ssl_context
  options[:redirect_limit] ||= @redirect_limit

  with_error_handling do
    resp = @client.get(to_url(path), headers: headers, options: options)
    resp.nethttp
  end
end

#head(path, headers = {}, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/puppet/network/http/connection_adapter.rb', line 32

def head(path, headers = {}, options = {})
  headers ||= {}
  options[:ssl_context] ||= resolve_ssl_context
  options[:redirect_limit] ||= @redirect_limit

  with_error_handling do
    resp = @client.head(to_url(path), headers: headers, options: options)
    resp.nethttp
  end
end

#post(path, data, headers = nil, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/network/http/connection_adapter.rb', line 19

def post(path, data, headers = nil, options = {})
  headers ||= {}
  headers['Content-Type'] ||= "application/x-www-form-urlencoded"
  data ||= ''
  options[:ssl_context] ||= resolve_ssl_context
  options[:redirect_limit] ||= @redirect_limit

  with_error_handling do
    resp = @client.post(to_url(path), data, headers: headers, options: options)
    resp.nethttp
  end
end

#put(path, data, headers = nil, options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppet/network/http/connection_adapter.rb', line 54

def put(path, data, headers = nil, options = {})
  headers ||= {}
  headers['Content-Type'] ||= "application/x-www-form-urlencoded"
  data ||= ''
  options[:ssl_context] ||= resolve_ssl_context
  options[:redirect_limit] ||= @redirect_limit

  with_error_handling do
    resp = @client.put(to_url(path), data, headers: headers, options: options)
    resp.nethttp
  end
end

#request_get(*args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/puppet/network/http/connection_adapter.rb', line 67

def request_get(*args, &block)
  path, headers = *args
  headers ||= {}
  options = {
    ssl_context: resolve_ssl_context,
    redirect_limit: @redirect_limit
  }

  resp = @client.get(to_url(path), headers: headers, options: options) do |response|
    yield response.nethttp if block_given?
  end
  resp.nethttp
end

#request_head(*args) {|response.nethttp| ... } ⇒ Object

Yields:

  • (response.nethttp)


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/puppet/network/http/connection_adapter.rb', line 81

def request_head(*args, &block)
  path, headers = *args
  headers ||= {}
  options = {
    ssl_context: resolve_ssl_context,
    redirect_limit: @redirect_limit
  }

  response = @client.head(to_url(path), headers: headers, options: options)
  yield response.nethttp if block_given?
  response.nethttp
end

#request_post(*args, &block) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/puppet/network/http/connection_adapter.rb', line 94

def request_post(*args, &block)
  path, data, headers = *args
  headers ||= {}
  headers['Content-Type'] ||= "application/x-www-form-urlencoded"
  options = {
    ssl_context: resolve_ssl_context,
    redirect_limit: @redirect_limit
  }

  resp = @client.post(to_url(path), data, headers: headers, options: options) do |response|
    yield response.nethttp if block_given?
  end
  resp.nethttp
end