diff --git a/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb b/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb index 65d0967b8f..a139fb8aa3 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb @@ -233,7 +233,6 @@ def __convert_to_json(o=nil, options={}) # @api private def __full_url(host) url = "#{host[:protocol]}://" - url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user] url += host[:host] url += ":#{host[:port]}" if host[:port] url += host[:path] if host[:path] diff --git a/elasticsearch-transport/lib/elasticsearch/transport/transport/http/faraday.rb b/elasticsearch-transport/lib/elasticsearch/transport/transport/http/faraday.rb index 860d77d4d9..8a968551c8 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/transport/http/faraday.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/transport/http/faraday.rb @@ -61,8 +61,12 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = # def __build_connection(host, options={}, block=nil) client = ::Faraday.new(__full_url(host), options, &block) + if host[:user] + auth = Base64.strict_encode64("#{host[:user]}:#{host[:password]}") + (options[:headers] ||= {}).merge!({'Authorization' => "Basic #{auth}"}) + end apply_headers(client, options) - Connections::Connection.new :host => host, :connection => client + Connections::Connection.new(host: host, connection: client) end # Returns an array of implementation specific connection errors.