class Hkp::Client
Constants
- MAX_REDIRECTS
Public Class Methods
new(server, ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER)
click to toggle source
# File lib/hkp.rb, line 17 def initialize(server, ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER) uri = URI server @host = uri.host @port = uri.port @use_ssl = false @ssl_verify_mode = ssl_verify_mode # set port and ssl flag according to URI scheme case uri.scheme.downcase when 'hkp' # use the HKP default port unless another port has been given @port ||= 11371 when /\A(hkp|http)s\z/ # hkps goes through 443 by default @port ||= 443 @use_ssl = true end @port ||= 80 end
Public Instance Methods
get(path, redirect_depth = 0)
click to toggle source
# File lib/hkp.rb, line 38 def get(path, redirect_depth = 0) Net::HTTP.start @host, @port, use_ssl: @use_ssl, verify_mode: @ssl_verify_mode do |http| request = Net::HTTP::Get.new path response = http.request request case response.code.to_i when 200 return response.body when 301, 302 if redirect_depth >= MAX_REDIRECTS raise TooManyRedirects else http_get response['location'], redirect_depth + 1 end else raise InvalidResponse, response.code end end end