Skip to content

Commit

Permalink
1. Remove KEY and CERT code duplicate; 2. Display error class as a pa…
Browse files Browse the repository at this point in the history
…rt of error message
  • Loading branch information
konstantin committed Dec 21, 2011
1 parent b768141 commit caf15f0
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/right_http_connection.rb
Expand Up @@ -207,7 +207,9 @@ def error_message
end

# add an error for a server
def error_add(message)
def error_add(error)
message = error
message = "#{error.class.name}: #{error.message}" if error.is_a?(Exception)
@state[@server] = { :count => error_count+1, :time => Time.now, :message => message }
end

Expand Down Expand Up @@ -341,21 +343,14 @@ def start(request_params)
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

# CERT
cert_file = get_param(:cert_file, request_params)
key_file = get_param(:key_file, request_params)
if (cert_file && File.exists?(cert_file)) && (key_file && File.exists?(key_file))
begin
@http.verify_callback = verifyCallbackProc
@http.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
@http.key = OpenSSL::PKey::RSA.new(File.read(key_file))
rescue OpenSSL::PKey::RSAError, OpenSSL::X509::CertificateError => e
@logger.error "##### Error loading SSL client cert or key: #{e.message} :: backtrace #{e.backtrace}"
raise e
end
end

cert = get_param(:cert, request_params)
key = get_param(:key, request_params)
cert = File.read(cert_file) if cert_file && File.exists?(cert_file)
cert ||= get_param(:cert, request_params)
# KEY
key_file = get_param(:key_file, request_params)
key = File.read(key_file) if key_file && File.exists?(key_file)
key ||= get_param(:key, request_params)
if cert && key
begin
@http.verify_callback = verifyCallbackProc
Expand All @@ -366,7 +361,6 @@ def start(request_params)
raise e
end
end

end
# open connection
@http.start
Expand Down Expand Up @@ -495,7 +489,7 @@ def request(request_params, &block)
raise e
end
# oops - we got a banana: log it
error_add(e.message)
error_add(e)
@logger.warn("#{err_header} request failure count: #{error_count}, exception: #{e.inspect}")

# We will be retrying the request, so reset the file pointer
Expand Down

0 comments on commit caf15f0

Please sign in to comment.