class Net::Hippie::Connection
A connection to a specific host
Public Class Methods
new(scheme, host, port, options = {})
click to toggle source
# File lib/net/hippie/connection.rb, line 7 def initialize(scheme, host, port, options = {}) http = Net::HTTP.new(host, port) http.read_timeout = options.fetch(:read_timeout, 10) http.open_timeout = options.fetch(:open_timeout, 10) http.use_ssl = scheme == 'https' http.verify_mode = options.fetch(:verify_mode, Net::Hippie.verify_mode) http.set_debug_output(options.fetch(:logger, Net::Hippie.logger)) apply_client_tls_to(http, options) @http = http end
Public Instance Methods
build_url_for(path)
click to toggle source
# File lib/net/hippie/connection.rb, line 22 def build_url_for(path) return path if path.start_with?('http') "#{@http.use_ssl? ? 'https' : 'http'}://#{@http.address}#{path}" end
run(request)
click to toggle source
# File lib/net/hippie/connection.rb, line 18 def run(request) @http.request(request) end
Private Instance Methods
apply_client_tls_to(http, options)
click to toggle source
# File lib/net/hippie/connection.rb, line 30 def apply_client_tls_to(http, options) return if options[:certificate].nil? || options[:key].nil? http.cert = OpenSSL::X509::Certificate.new(options[:certificate]) http.key = private_key(options[:key], options[:passphrase]) end
private_key(key, passphrase, type = OpenSSL::PKey::RSA)
click to toggle source
# File lib/net/hippie/connection.rb, line 37 def private_key(key, passphrase, type = OpenSSL::PKey::RSA) passphrase ? type.new(key, passphrase) : type.new(key) end