lib/elasticsearch/transport/client.rb in elasticsearch-transport-1.0.14 vs lib/elasticsearch/transport/client.rb in elasticsearch-transport-1.0.15
- old
+ new
@@ -54,10 +54,11 @@
#
# @option arguments [Integer] :sniffer_timeout Timeout for reloading connections in seconds (1 by default)
#
# @option arguments [Boolean,Number] :retry_on_failure Retry X times when request fails before raising and
# exception (false by default)
+ # @option arguments Array<Number> :retry_on_status Retry when specific status codes are returned
#
# @option arguments [Boolean] :reload_on_failure Reload connections after failure (false by default)
#
# @option arguments [Integer] :request_timeout The request timeout to be passed to transport in options
#
@@ -77,11 +78,13 @@
# {Elasticsearch::Transport::Transport::Connections::Selector::Base}.
#
# @option arguments [String] :send_get_body_as Specify the HTTP method to use for GET requests with a body.
# (Default: GET)
#
- def initialize(arguments={})
+ # @yield [faraday] Access and configure the `Faraday::Connection` instance directly with a block
+ #
+ def initialize(arguments={}, &block)
hosts = arguments[:hosts] || \
arguments[:host] || \
arguments[:url] || \
arguments[:urls] || \
ENV.fetch('ELASTICSEARCH_URL', 'localhost:9200')
@@ -101,10 +104,13 @@
transport_class = arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
@transport = arguments[:transport] || begin
if transport_class == Transport::HTTP::Faraday
transport_class.new(:hosts => __extract_hosts(hosts, arguments), :options => arguments) do |faraday|
- faraday.adapter(arguments[:adapter] || __auto_detect_adapter)
+ block.call faraday if block
+ unless (h = faraday.builder.handlers.last) && h.name.start_with?("Faraday::Adapter")
+ faraday.adapter(arguments[:adapter] || __auto_detect_adapter)
+ end
end
else
transport_class.new(:hosts => __extract_hosts(hosts, arguments), :options => arguments)
end
end