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, Base::SANITIZED_PASSWORD
Instance Attribute Summary
Attributes included from Base
#connections, #counter, #hosts, #last_request_at, #logger, #options, #protocol, #reload_after, #reload_connections, #resurrect_after, #serializer, #sniffer, #tracer
Instance Method Summary collapse
-
#__build_connection(host, options = {}, block = nil) ⇒ Connections::Connection
Builds and returns a connection.
- #headers(connection) ⇒ Object
-
#host_unreachable_exceptions ⇒ Array
Returns an array of implementation specific connection errors.
-
#perform_request(method, path, params = {}, body = nil, headers = nil, opts = {}) ⇒ Response
Performs the request by invoking Base#perform_request with a block.
Methods included from Base
#__build_connections, #__close_connections, #__convert_to_json, #__full_url, #__log_response, #__raise_transport_error, #__rebuild_connections, #__trace, #get_connection, #initialize, #reload_connections!, #resurrect_dead_connections!
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn
Instance Method Details
#__build_connection(host, options = {}, block = nil) ⇒ Connections::Connection
Builds and returns a connection
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 86 def __build_connection(host, ={}, block=nil) client = ::Curl::Easy.new apply_headers(client, ) 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 end |
#headers(connection) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 68 def headers(connection) headers_string = connection.connection.header_str return nil if headers_string.nil? response_headers = headers_string&.split(/\\r\\n|\r\n/).reject(&:empty?) response_headers.shift # Removes HTTP status string processed_header = response_headers.flat_map { |s| s.scan(/^(\S+): (.+)/) } headers_hash = Hash[processed_header].transform_keys(&:downcase) if headers_hash['content-type']&.match?(/application\/json/) headers_hash['content-type'] = 'application/json' end headers_hash end |
#host_unreachable_exceptions ⇒ Array
Returns an array of implementation specific connection errors.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/elasticsearch/transport/transport/http/curb.rb', line 106 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, headers = nil, opts = {}) ⇒ Response
Performs the request by invoking Base#perform_request with a block.
33 34 35 36 37 38 39 40 41 42 43 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 33 def perform_request(method, path, params={}, body=nil, headers=nil, opts={}) super do |connection, _url| connection.connection.url = connection.full_url(path, params) body = body ? __convert_to_json(body) : nil body, headers = compress_request(body, headers) case method when 'HEAD' connection.connection.set :nobody, true when 'GET', 'POST', 'PUT', 'DELETE' connection.connection.set :nobody, false connection.connection.put_data = body if body if headers if connection.connection.headers connection.connection.headers.merge!(headers) else connection.connection.headers = headers end end else raise ArgumentError, "Unsupported HTTP method: #{method}" end connection.connection.http(method.to_sym) Response.new( connection.connection.response_code, decompress_response(connection.connection.body_str), headers(connection) ) end end |