Class: Elasticsearch::Transport::Transport::HTTP::Faraday

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/elasticsearch/transport/transport/http/faraday.rb

Overview

The default transport implementation, using the [Faraday](rubygems.org/gems/faraday) library for abstracting the HTTP client.

See Also:

Constant Summary

Constants included from Base

Base::DEFAULT_MAX_RETRIES, Base::DEFAULT_PORT, Base::DEFAULT_PROTOCOL, Base::DEFAULT_RELOAD_AFTER, Base::DEFAULT_RESURRECT_AFTER, Base::DEFAULT_SERIALIZER_CLASS

Instance Attribute Summary

Attributes included from Base

#connections, #counter, #hosts, #last_request_at, #logger, #max_retries, #options, #protocol, #reload_after, #reload_connections, #resurrect_after, #serializer, #sniffer, #tracer

Instance Method Summary collapse

Methods included from Base

#__convert_to_json, #__full_url, #__log, #__log_failed, #__raise_transport_error, #__rebuild_connections, #__trace, #get_connection, #initialize, #reload_connections!, #resurrect_dead_connections!

Instance Method Details

#__build_connectionsConnections::Collection

Builds and returns a collection of connections.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/elasticsearch/transport/transport/http/faraday.rb', line 34

def __build_connections
  Connections::Collection.new \
    :connections => hosts.map { |host|
      host[:protocol]   = host[:scheme] || DEFAULT_PROTOCOL
      host[:port]     ||= DEFAULT_PORT
      url               = __full_url(host)

      Connections::Connection.new \
        :host => host,
        :connection => ::Faraday::Connection.new(url, (options[:transport_options] || {}), &@block )
    },
    :selector_class => options[:selector_class],
    :selector => options[:selector]
end

#host_unreachable_exceptionsArray

Returns an array of implementation specific connection errors.

Returns:

  • (Array)


53
54
55
# File 'lib/elasticsearch/transport/transport/http/faraday.rb', line 53

def host_unreachable_exceptions
  [::Faraday::Error::ConnectionFailed, ::Faraday::Error::TimeoutError]
end

#perform_request(method, path, params = {}, body = nil) ⇒ Response

Performs the request by invoking Base#perform_request with a block.

Returns:

See Also:



19
20
21
22
23
24
25
26
27
28
# File 'lib/elasticsearch/transport/transport/http/faraday.rb', line 19

def perform_request(method, path, params={}, body=nil)
  super do |connection, url|
    response = connection.connection.run_request \
      method.downcase.to_sym,
      url,
      ( body ? __convert_to_json(body) : nil ),
      {}
    Response.new response.status, response.body, response.headers
  end
end