lib/elasticsearch/transport/transport/base.rb in elasticsearch-transport-1.0.15 vs lib/elasticsearch/transport/transport/base.rb in elasticsearch-transport-1.0.16.pre

- old
+ new

@@ -9,10 +9,11 @@ DEFAULT_PROTOCOL = 'http' DEFAULT_RELOAD_AFTER = 10_000 # Requests DEFAULT_RESURRECT_AFTER = 60 # Seconds DEFAULT_MAX_RETRIES = 3 # Requests DEFAULT_SERIALIZER_CLASS = Serializer::MultiJson + SANITIZED_PASSWORD = '*'*rand(15) attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol attr_accessor :serializer, :sniffer, :logger, :tracer, :reload_connections, :reload_after, :resurrect_after, :max_retries @@ -26,10 +27,12 @@ # @option arguments [Array] :options A Hash with options (usually passed by {Client}) # # @see Client#initialize # def initialize(arguments={}, &block) + @state_mutex = Mutex.new + @hosts = arguments[:hosts] || [] @options = arguments[:options] || {} @block = block @connections = __build_connections @@ -92,14 +95,16 @@ # Replaces the connections collection. # # @api private # def __rebuild_connections(arguments={}) - @hosts = arguments[:hosts] || [] - @options = arguments[:options] || {} - __close_connections - @connections = __build_connections + @state_mutex.synchronize do + @hosts = arguments[:hosts] || [] + @options = arguments[:options] || {} + __close_connections + @connections = __build_connections + end end # Closes the connections collection. # # @api private @@ -111,11 +116,12 @@ # Log request and response information. # # @api private # def __log(method, path, params, body, url, response, json, took, duration) - logger.info "#{method.to_s.upcase} #{url} " + + sanitized_url = url.to_s.gsub(/\/\/(.+):(.+)@/, '//' + '\1:' + SANITIZED_PASSWORD + '@') + logger.info "#{method.to_s.upcase} #{sanitized_url} " + "[status:#{response.status}, request:#{sprintf('%.3fs', duration)}, query:#{took}]" logger.debug "> #{__convert_to_json(body)}" if body logger.debug "< #{response.body}" end @@ -158,10 +164,10 @@ # @param host [Hash] Host configuration passed in from {Client} # # @api private def __full_url(host) url = "#{host[:protocol]}://" - url += "#{host[:user]}:#{host[:password]}@" if host[:user] + url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user] url += "#{host[:host]}:#{host[:port]}" url += "#{host[:path]}" if host[:path] url end