Class: Elasticsearch::Transport::Transport::HTTP::Curb
- Inherits:
-
Object
- Object
- Elasticsearch::Transport::Transport::HTTP::Curb
- Includes:
- Base
- Defined in:
- lib/elasticsearch/transport/transport/http/curb.rb
Overview
Alternative HTTP transport implementation, using the [Curb](rubygems.org/gems/curb) client.
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
-
#__build_connections ⇒ Connections::Collection
Builds and returns a collection of connections.
-
#host_unreachable_exceptions ⇒ Array
Returns an array of implementation specific connection errors.
-
#perform_request(method, path, params = {}, body = nil) ⇒ Response
Performs the request by invoking Base#perform_request with a block.
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_connections ⇒ Connections::Collection
Builds and returns a collection of connections.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 44 def __build_connections Connections::Collection.new \ :connections => hosts.map { |host| host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL host[:port] ||= DEFAULT_PORT client = ::Curl::Easy.new client.headers = {'User-Agent' => "Curb #{Curl::CURB_VERSION}"} client.url = __full_url(host) if host[:user] client.http_auth_types = host[:auth_type] || :basic client.username = host[:user] client.password = host[:password] end client.instance_eval &@block if @block Connections::Connection.new :host => host, :connection => client }, :selector_class => [:selector_class], :selector => [:selector] end |
#host_unreachable_exceptions ⇒ Array
Returns an array of implementation specific connection errors.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 72 def host_unreachable_exceptions [ ::Curl::Err::HostResolutionError, ::Curl::Err::ConnectionFailedError, ::Curl::Err::GotNothingError, ::Curl::Err::RecvError, ::Curl::Err::SendError, ::Curl::Err::TimeoutError ] end |
#perform_request(method, path, params = {}, body = nil) ⇒ Response
Performs the request by invoking Base#perform_request with a block.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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' when 'GET', 'POST', 'PUT', 'DELETE' connection.connection.put_data = __convert_to_json(body) if body else raise ArgumentError, "Unsupported HTTP method: #{method}" end connection.connection.http(method.to_sym) headers = {} headers['content-type'] = 'application/json' if connection.connection.header_str =~ /\/json/ Response.new connection.connection.response_code, connection.connection.body_str, headers end end |