Module: Beaker::DSL::Helpers::WebHelpers
- Defined in:
- lib/beaker-http/dsl/web_helpers.rb
Instance Method Summary collapse
-
#generate_new_http_connection(host = nil) ⇒ Beaker::Http::Connection
Generates a new http connection object, using the ever-present options hash to configure the connection.
-
#http_request(url, request_method, cert = nil, key = nil, body = nil, options = {}) ⇒ Faraday::Response
Make a single http request and discard the http connection object.
Instance Method Details
#generate_new_http_connection(host = nil) ⇒ Beaker::Http::Connection
Generates a new http connection object, using the ever-present options hash to configure the connection.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/beaker-http/dsl/web_helpers.rb', line 9 def generate_new_http_connection(host = nil) if host raise ArgumentError.new "host must be Beaker::Host, not #{host.class}" if !host.is_a?(Beaker::Host) connection = Beaker::Http::Connection.new(host.) connection.configure_private_key_and_cert_with_puppet(host) connection else Beaker::Http::Connection.new() end end |
#http_request(url, request_method, cert = nil, key = nil, body = nil, options = {}) ⇒ Faraday::Response
Make a single http request and discard the http connection object. Returns a Faraday::Response object that can be introspected for all response information.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/beaker-http/dsl/web_helpers.rb', line 32 def http_request(url, request_method, cert=nil, key=nil, body=nil, ={}) connection = generate_new_http_connection connection.url_prefix = URI.parse(url) if cert if cert.is_a?(OpenSSL::X509::Certificate) connection.ssl['client_cert'] = cert else raise TypeError, "cert must be an OpenSSL::X509::Certificate object, not #{cert.class}" end end if key if key.is_a?(OpenSSL::PKey::RSA) connection.ssl['client_key'] = key else raise TypeError, "key must be an OpenSSL::PKey:RSA object, not #{key.class}" end end # ewwww connection.ssl[:verify] = false connection.connection..timeout = [:read_timeout] if [:read_timeout] response = connection.send(request_method) { |conn| conn.body = body } response end |