Class: Elasticsearch::Transport::Transport::HTTP::Curb

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

Overview

Alternative HTTP transport implementation, using the [Curb](rubygems.org/gems/curb) client.

See Also:

Constant Summary

Constants included from Base

Base::DEFAULT_MAX_TRIES, 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_tries, #options, #protocol, #reload_after, #resurrect_after, #serializer, #sniffer, #tracer

Instance Method Summary collapse

Methods included from Base

#__convert_to_json, #__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.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 40

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

      client = ::Curl::Easy.new
      client.resolve_mode = :ipv4
      client.headers      = {'Content-Type' => 'application/json'}
      client.url          = "#{host[:protocol]}://#{host[:host]}:#{host[:port]}"

      client.instance_eval &@block if @block

      Connections::Connection.new :host => host, :connection => client
    },
    :selector => options[:selector]
end

#host_unreachable_exceptionsArray

Returns an array of implementation specific connection errors.

Returns:

  • (Array)


62
63
64
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 62

def host_unreachable_exceptions
  [::Curl::Err::HostResolutionError, ::Curl::Err::ConnectionFailedError]
end

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

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

Returns:

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 18

def perform_request(method, path, params={}, body=nil)
  super do |connection,url|
    connection.connection.url = url

    case method
      when 'HEAD', 'GET' then connection.connection.http method.downcase.to_sym
      when 'PUT'         then connection.connection.http_put serializer.dump(body)
      when 'DELETE'      then connection.connection.http_delete
      when 'POST'
        connection.connection.post_body = __convert_to_json(body) if body
        connection.connection.http_post
      else raise ArgumentError, "Unsupported HTTP method: #{method}"
    end

    Response.new connection.connection.response_code, connection.connection.body_str
  end
end