Permalink
Browse files

SSL: Reestablish connection when any of key/cert has changed

  • Loading branch information...
konstantin
konstantin committed Jul 17, 2012
1 parent caf15f0 commit 901bc8d572f3f95cf3539ad34f5d326b2b9edd1d
Showing with 10 additions and 3 deletions.
  1. +10 −3 lib/right_http_connection.rb
@@ -393,6 +393,11 @@ def start(request_params)
=end
def request(request_params, &block)
+ # Re-establish the connection if any of auth params has changed
+ same_auth_params_as_before = [:cert, :key, :cert_file, :key_file, :ca_file].select do |param|
+ request_params[param] != get_param(param)
+ end.empty?
+
current_params = @params.merge(request_params)
exception = get_param(:exception, current_params) || RuntimeError
@@ -401,9 +406,10 @@ def request(request_params, &block)
loop do
current_params[:protocol] ||= (current_params[:port] == 443 ? 'https' : 'http')
# (re)open connection to server if none exists or params has changed
- same_server_as_before = @server == current_params[:server] &&
- @port == current_params[:port] &&
- @protocol == current_params[:protocol]
+ same_server_as_before = @server == current_params[:server] &&
+ @port == current_params[:port] &&
+ @protocol == current_params[:protocol] &&
+ same_auth_params_as_before
# if we are inside a delay between retries: no requests this time!
# (skip this step if the endpoint has changed)
@@ -427,6 +433,7 @@ def request(request_params, &block)
@http.started? &&
same_server_as_before
start(current_params)
+ same_auth_params_as_before = true
end
# Detect if the body is a streamable object like a file or socket. If so, stream that

0 comments on commit 901bc8d

Please sign in to comment.