elasticsearch-transport 7.1.0 → 7.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +12 -8
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +160 -72
- data/Rakefile +1 -1
- data/elasticsearch-transport.gemspec +42 -60
- data/lib/elasticsearch/transport/client.rb +70 -19
- data/lib/elasticsearch/transport/redacted.rb +1 -1
- data/lib/elasticsearch/transport/transport/base.rb +86 -12
- data/lib/elasticsearch/transport/transport/connections/collection.rb +1 -1
- data/lib/elasticsearch/transport/transport/connections/connection.rb +1 -1
- data/lib/elasticsearch/transport/transport/connections/selector.rb +18 -6
- data/lib/elasticsearch/transport/transport/errors.rb +1 -1
- data/lib/elasticsearch/transport/transport/http/curb.rb +26 -9
- data/lib/elasticsearch/transport/transport/http/faraday.rb +18 -4
- data/lib/elasticsearch/transport/transport/http/manticore.rb +25 -10
- data/lib/elasticsearch/transport/transport/loggable.rb +1 -1
- data/lib/elasticsearch/transport/transport/response.rb +1 -2
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +1 -1
- data/lib/elasticsearch/transport/transport/sniffer.rb +3 -2
- data/lib/elasticsearch/transport/version.rb +2 -2
- data/lib/elasticsearch/transport.rb +1 -1
- data/lib/elasticsearch-transport.rb +1 -1
- data/spec/elasticsearch/connections/collection_spec.rb +254 -0
- data/spec/elasticsearch/connections/selector_spec.rb +174 -0
- data/spec/elasticsearch/transport/base_spec.rb +177 -9
- data/spec/elasticsearch/transport/client_spec.rb +525 -29
- data/spec/elasticsearch/transport/sniffer_spec.rb +1 -1
- data/spec/spec_helper.rb +25 -1
- data/test/integration/transport_test.rb +1 -1
- data/test/profile/client_benchmark_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/connection_test.rb +1 -1
- data/test/unit/response_test.rb +2 -2
- data/test/unit/serializer_test.rb +1 -1
- data/test/unit/transport_base_test.rb +1 -1
- data/test/unit/transport_curb_test.rb +2 -2
- data/test/unit/transport_faraday_test.rb +1 -1
- data/test/unit/transport_manticore_test.rb +28 -12
- metadata +85 -61
- data/test/unit/connection_collection_test.rb +0 -147
- data/test/unit/connection_selector_test.rb +0 -81
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -35,7 +35,7 @@ module Elasticsearch
|
|
35
35
|
attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol
|
36
36
|
attr_accessor :serializer, :sniffer, :logger, :tracer,
|
37
37
|
:reload_connections, :reload_after,
|
38
|
-
:resurrect_after
|
38
|
+
:resurrect_after
|
39
39
|
|
40
40
|
# Creates a new transport object
|
41
41
|
#
|
@@ -56,6 +56,7 @@ module Elasticsearch
|
|
56
56
|
@options[:retry_on_status] ||= []
|
57
57
|
|
58
58
|
@block = block
|
59
|
+
@compression = !!@options[:compression]
|
59
60
|
@connections = __build_connections
|
60
61
|
|
61
62
|
@serializer = options[:serializer] || ( options[:serializer_class] ? options[:serializer_class].new(self) : DEFAULT_SERIALIZER_CLASS.new(self) )
|
@@ -71,7 +72,6 @@ module Elasticsearch
|
|
71
72
|
@reload_connections = options[:reload_connections]
|
72
73
|
@reload_after = options[:reload_connections].is_a?(Integer) ? options[:reload_connections] : DEFAULT_RELOAD_AFTER
|
73
74
|
@resurrect_after = options[:resurrect_after] || DEFAULT_RESURRECT_AFTER
|
74
|
-
@max_retries = options[:retry_on_failure].is_a?(Integer) ? options[:retry_on_failure] : DEFAULT_MAX_RETRIES
|
75
75
|
@retry_on_status = Array(options[:retry_on_status]).map { |d| d.to_i }
|
76
76
|
end
|
77
77
|
|
@@ -202,7 +202,7 @@ module Elasticsearch
|
|
202
202
|
( params.empty? ? '' : "&#{::Faraday::Utils::ParamsHash[params].to_query}" )
|
203
203
|
trace_body = body ? " -d '#{__convert_to_json(body, :pretty => true)}'" : ''
|
204
204
|
trace_command = "curl -X #{method.to_s.upcase}"
|
205
|
-
trace_command += " -H '#{headers.
|
205
|
+
trace_command += " -H '#{headers.collect { |k,v| "#{k}: #{v}" }.join(", ")}'" if headers && !headers.empty?
|
206
206
|
trace_command += " '#{trace_url}'#{trace_body}\n"
|
207
207
|
tracer.info trace_command
|
208
208
|
tracer.debug "# #{Time.now.iso8601} [#{response.status}] (#{format('%.3f', duration)}s)\n#"
|
@@ -234,7 +234,8 @@ module Elasticsearch
|
|
234
234
|
def __full_url(host)
|
235
235
|
url = "#{host[:protocol]}://"
|
236
236
|
url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user]
|
237
|
-
url += "#{host[:host]}
|
237
|
+
url += "#{host[:host]}"
|
238
|
+
url += ":#{host[:port]}" if host[:port]
|
238
239
|
url += "#{host[:path]}" if host[:path]
|
239
240
|
url
|
240
241
|
end
|
@@ -257,10 +258,17 @@ module Elasticsearch
|
|
257
258
|
# @raise [ServerError] If request failed on server
|
258
259
|
# @raise [Error] If no connection is available
|
259
260
|
#
|
260
|
-
def perform_request(method, path, params={}, body=nil, headers=nil, &block)
|
261
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={}, &block)
|
261
262
|
raise NoMethodError, "Implement this method in your transport class" unless block_given?
|
262
263
|
start = Time.now
|
263
264
|
tries = 0
|
265
|
+
reload_on_failure = opts.fetch(:reload_on_failure, @options[:reload_on_failure])
|
266
|
+
|
267
|
+
max_retries = if opts.key?(:retry_on_failure)
|
268
|
+
opts[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : opts[:retry_on_failure]
|
269
|
+
elsif options.key?(:retry_on_failure)
|
270
|
+
options[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : options[:retry_on_failure]
|
271
|
+
end
|
264
272
|
|
265
273
|
params = params.clone
|
266
274
|
|
@@ -286,7 +294,7 @@ module Elasticsearch
|
|
286
294
|
rescue Elasticsearch::Transport::Transport::ServerError => e
|
287
295
|
if response && @retry_on_status.include?(response.status)
|
288
296
|
log_warn "[#{e.class}] Attempt #{tries} to get response from #{url}"
|
289
|
-
if tries <= max_retries
|
297
|
+
if tries <= (max_retries || DEFAULT_MAX_RETRIES)
|
290
298
|
retry
|
291
299
|
else
|
292
300
|
log_fatal "[#{e.class}] Cannot get response from #{url} after #{tries} tries"
|
@@ -301,12 +309,12 @@ module Elasticsearch
|
|
301
309
|
|
302
310
|
connection.dead!
|
303
311
|
|
304
|
-
if
|
312
|
+
if reload_on_failure and tries < connections.all.size
|
305
313
|
log_warn "[#{e.class}] Reloading connections (attempt #{tries} of #{connections.all.size})"
|
306
314
|
reload_connections! and retry
|
307
315
|
end
|
308
316
|
|
309
|
-
if
|
317
|
+
if max_retries
|
310
318
|
log_warn "[#{e.class}] Attempt #{tries} connecting to #{connection.host.inspect}"
|
311
319
|
if tries <= max_retries
|
312
320
|
retry
|
@@ -328,7 +336,7 @@ module Elasticsearch
|
|
328
336
|
|
329
337
|
if response.status.to_i >= 300
|
330
338
|
__log_response method, path, params, body, url, response, nil, 'N/A', duration
|
331
|
-
__trace method, path, params, headers, body, url, response, nil, 'N/A', duration if tracer
|
339
|
+
__trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', duration if tracer
|
332
340
|
|
333
341
|
# Log the failure only when `ignore` doesn't match the response status
|
334
342
|
unless ignore.include?(response.status.to_i)
|
@@ -345,7 +353,9 @@ module Elasticsearch
|
|
345
353
|
__log_response method, path, params, body, url, response, json, took, duration
|
346
354
|
end
|
347
355
|
|
348
|
-
__trace
|
356
|
+
__trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', duration if tracer
|
357
|
+
|
358
|
+
warnings(response.headers['warning']) if response.headers&.[]('warning')
|
349
359
|
|
350
360
|
Response.new response.status, json || response.body, response.headers
|
351
361
|
ensure
|
@@ -360,7 +370,71 @@ module Elasticsearch
|
|
360
370
|
def host_unreachable_exceptions
|
361
371
|
[Errno::ECONNREFUSED]
|
362
372
|
end
|
373
|
+
|
374
|
+
private
|
375
|
+
|
376
|
+
USER_AGENT_STR = 'User-Agent'.freeze
|
377
|
+
USER_AGENT_REGEX = /user\-?\_?agent/
|
378
|
+
CONTENT_TYPE_STR = 'Content-Type'.freeze
|
379
|
+
CONTENT_TYPE_REGEX = /content\-?\_?type/
|
380
|
+
DEFAULT_CONTENT_TYPE = 'application/json'.freeze
|
381
|
+
GZIP = 'gzip'.freeze
|
382
|
+
ACCEPT_ENCODING = 'Accept-Encoding'.freeze
|
383
|
+
GZIP_FIRST_TWO_BYTES = '1f8b'.freeze
|
384
|
+
HEX_STRING_DIRECTIVE = 'H*'.freeze
|
385
|
+
RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
|
386
|
+
|
387
|
+
def decompress_response(body)
|
388
|
+
return body unless use_compression?
|
389
|
+
return body unless gzipped?(body)
|
390
|
+
|
391
|
+
io = StringIO.new(body)
|
392
|
+
gzip_reader = if RUBY_ENCODING
|
393
|
+
Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT')
|
394
|
+
else
|
395
|
+
Zlib::GzipReader.new(io)
|
396
|
+
end
|
397
|
+
gzip_reader.read
|
398
|
+
end
|
399
|
+
|
400
|
+
def gzipped?(body)
|
401
|
+
body[0..1].unpack(HEX_STRING_DIRECTIVE)[0] == GZIP_FIRST_TWO_BYTES
|
402
|
+
end
|
403
|
+
|
404
|
+
def use_compression?
|
405
|
+
@compression
|
406
|
+
end
|
407
|
+
|
408
|
+
def apply_headers(client, options)
|
409
|
+
headers = options[:headers] || {}
|
410
|
+
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
411
|
+
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header(client)
|
412
|
+
client.headers[ACCEPT_ENCODING] = GZIP if use_compression?
|
413
|
+
client.headers.merge!(headers)
|
414
|
+
end
|
415
|
+
|
416
|
+
def find_value(hash, regex)
|
417
|
+
key_value = hash.find { |k,v| k.to_s.downcase =~ regex }
|
418
|
+
if key_value
|
419
|
+
hash.delete(key_value[0])
|
420
|
+
key_value[1]
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
def user_agent_header(client)
|
425
|
+
@user_agent ||= begin
|
426
|
+
meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
|
427
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
428
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
429
|
+
end
|
430
|
+
"elasticsearch-ruby/#{VERSION} (#{meta.join('; ')})"
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def warnings(warning)
|
435
|
+
warn("warning: #{warning}")
|
436
|
+
end
|
363
437
|
end
|
364
438
|
end
|
365
439
|
end
|
366
|
-
end
|
440
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -61,18 +61,30 @@ module Elasticsearch
|
|
61
61
|
class RoundRobin
|
62
62
|
include Base
|
63
63
|
|
64
|
+
# @option arguments [Connections::Collection] :connections Collection with connections.
|
65
|
+
#
|
66
|
+
def initialize(arguments = {})
|
67
|
+
super
|
68
|
+
@mutex = Mutex.new
|
69
|
+
@current = nil
|
70
|
+
end
|
71
|
+
|
64
72
|
# Returns the next connection from the collection, rotating them in round-robin fashion.
|
65
73
|
#
|
66
74
|
# @return [Connections::Connection]
|
67
75
|
#
|
68
76
|
def select(options={})
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
77
|
+
@mutex.synchronize do
|
78
|
+
conns = connections
|
79
|
+
if @current && (@current < conns.size-1)
|
80
|
+
@current += 1
|
81
|
+
else
|
82
|
+
@current = 0
|
83
|
+
end
|
84
|
+
conns[@current]
|
85
|
+
end
|
73
86
|
end
|
74
87
|
end
|
75
|
-
|
76
88
|
end
|
77
89
|
end
|
78
90
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -32,7 +32,7 @@ module Elasticsearch
|
|
32
32
|
# @return [Response]
|
33
33
|
# @see Transport::Base#perform_request
|
34
34
|
#
|
35
|
-
def perform_request(method, path, params={}, body=nil, headers=nil)
|
35
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
36
36
|
super do |connection, url|
|
37
37
|
connection.connection.url = connection.full_url(path, params)
|
38
38
|
|
@@ -43,7 +43,15 @@ module Elasticsearch
|
|
43
43
|
connection.connection.set :nobody, false
|
44
44
|
|
45
45
|
connection.connection.put_data = __convert_to_json(body) if body
|
46
|
-
|
46
|
+
|
47
|
+
if headers
|
48
|
+
if connection.connection.headers
|
49
|
+
connection.connection.headers.merge!(headers)
|
50
|
+
else
|
51
|
+
connection.connection.headers = headers
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
47
55
|
else raise ArgumentError, "Unsupported HTTP method: #{method}"
|
48
56
|
end
|
49
57
|
|
@@ -53,7 +61,7 @@ module Elasticsearch
|
|
53
61
|
response_headers['content-type'] = 'application/json' if connection.connection.header_str =~ /\/json/
|
54
62
|
|
55
63
|
Response.new connection.connection.response_code,
|
56
|
-
connection.connection.body_str,
|
64
|
+
decompress_response(connection.connection.body_str),
|
57
65
|
response_headers
|
58
66
|
end
|
59
67
|
end
|
@@ -65,10 +73,7 @@ module Elasticsearch
|
|
65
73
|
def __build_connection(host, options={}, block=nil)
|
66
74
|
client = ::Curl::Easy.new
|
67
75
|
|
68
|
-
|
69
|
-
headers.update('User-Agent' => "Curb #{Curl::CURB_VERSION}")
|
70
|
-
|
71
|
-
client.headers = headers
|
76
|
+
apply_headers(client, options)
|
72
77
|
client.url = __full_url(host)
|
73
78
|
|
74
79
|
if host[:user]
|
@@ -96,8 +101,20 @@ module Elasticsearch
|
|
96
101
|
::Curl::Err::TimeoutError
|
97
102
|
]
|
98
103
|
end
|
99
|
-
end
|
100
104
|
|
105
|
+
private
|
106
|
+
|
107
|
+
def user_agent_header(client)
|
108
|
+
@user_agent ||= begin
|
109
|
+
meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
|
110
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
111
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
112
|
+
end
|
113
|
+
meta << "Curb #{Curl::CURB_VERSION}"
|
114
|
+
"elasticsearch-ruby/#{VERSION} (#{meta.join('; ')})"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
101
118
|
end
|
102
119
|
end
|
103
120
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -33,7 +33,7 @@ module Elasticsearch
|
|
33
33
|
# @return [Response]
|
34
34
|
# @see Transport::Base#perform_request
|
35
35
|
#
|
36
|
-
def perform_request(method, path, params={}, body=nil, headers=nil)
|
36
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
37
37
|
super do |connection, url|
|
38
38
|
headers = headers || connection.connection.headers
|
39
39
|
|
@@ -42,7 +42,7 @@ module Elasticsearch
|
|
42
42
|
( body ? __convert_to_json(body) : nil ),
|
43
43
|
headers)
|
44
44
|
|
45
|
-
Response.new response.status, response.body, response.headers
|
45
|
+
Response.new response.status, decompress_response(response.body), response.headers
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -52,6 +52,7 @@ module Elasticsearch
|
|
52
52
|
#
|
53
53
|
def __build_connection(host, options={}, block=nil)
|
54
54
|
client = ::Faraday.new(__full_url(host), options, &block)
|
55
|
+
apply_headers(client, options)
|
55
56
|
Connections::Connection.new :host => host, :connection => client
|
56
57
|
end
|
57
58
|
|
@@ -60,7 +61,20 @@ module Elasticsearch
|
|
60
61
|
# @return [Array]
|
61
62
|
#
|
62
63
|
def host_unreachable_exceptions
|
63
|
-
[::Faraday::
|
64
|
+
[::Faraday::ConnectionFailed, ::Faraday::TimeoutError]
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def user_agent_header(client)
|
70
|
+
@user_agent ||= begin
|
71
|
+
meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
|
72
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
73
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
74
|
+
end
|
75
|
+
meta << "#{client.headers[USER_AGENT_STR]}"
|
76
|
+
"elasticsearch-ruby/#{VERSION} (#{meta.join('; ')})"
|
77
|
+
end
|
64
78
|
end
|
65
79
|
end
|
66
80
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -80,7 +80,7 @@ module Elasticsearch
|
|
80
80
|
# @return [Response]
|
81
81
|
# @see Transport::Base#perform_request
|
82
82
|
#
|
83
|
-
def perform_request(method, path, params={}, body=nil, headers=nil)
|
83
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
84
84
|
super do |connection, url|
|
85
85
|
params[:body] = __convert_to_json(body) if body
|
86
86
|
params[:headers] = headers if headers
|
@@ -110,14 +110,8 @@ module Elasticsearch
|
|
110
110
|
#
|
111
111
|
def __build_connections
|
112
112
|
@request_options = {}
|
113
|
-
|
114
|
-
|
115
|
-
@request_options[:headers] = options[:transport_options][:headers]
|
116
|
-
end
|
117
|
-
|
118
|
-
if options.key?(:headers)
|
119
|
-
@request_options[:headers] = options[:headers]
|
120
|
-
end
|
113
|
+
apply_headers(@request_options, options[:transport_options])
|
114
|
+
apply_headers(@request_options, options)
|
121
115
|
|
122
116
|
Connections::Collection.new \
|
123
117
|
:connections => hosts.map { |host|
|
@@ -157,6 +151,27 @@ module Elasticsearch
|
|
157
151
|
::Manticore::ResolutionFailure
|
158
152
|
]
|
159
153
|
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def apply_headers(request_options, options)
|
158
|
+
headers = (options && options[:headers]) || {}
|
159
|
+
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
160
|
+
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header
|
161
|
+
headers[ACCEPT_ENCODING] = GZIP if use_compression?
|
162
|
+
request_options.merge!(headers: headers)
|
163
|
+
end
|
164
|
+
|
165
|
+
def user_agent_header
|
166
|
+
@user_agent ||= begin
|
167
|
+
meta = ["RUBY_VERSION: #{JRUBY_VERSION}"]
|
168
|
+
if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
|
169
|
+
meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
|
170
|
+
end
|
171
|
+
meta << "Manticore #{::Manticore::VERSION}"
|
172
|
+
"elasticsearch-ruby/#{VERSION} (#{meta.join('; ')})"
|
173
|
+
end
|
174
|
+
end
|
160
175
|
end
|
161
176
|
end
|
162
177
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -18,7 +18,6 @@
|
|
18
18
|
module Elasticsearch
|
19
19
|
module Transport
|
20
20
|
module Transport
|
21
|
-
|
22
21
|
# Wraps the response from Elasticsearch.
|
23
22
|
#
|
24
23
|
class Response
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -45,7 +45,8 @@ module Elasticsearch
|
|
45
45
|
#
|
46
46
|
def hosts
|
47
47
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
48
|
-
nodes = transport.perform_request('GET', '_nodes/http'
|
48
|
+
nodes = transport.perform_request('GET', '_nodes/http', {}, nil, nil,
|
49
|
+
reload_on_failure: false).body
|
49
50
|
|
50
51
|
hosts = nodes['nodes'].map do |id, info|
|
51
52
|
if info[PROTOCOL]
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -17,6 +17,6 @@
|
|
17
17
|
|
18
18
|
module Elasticsearch
|
19
19
|
module Transport
|
20
|
-
VERSION = "7.
|
20
|
+
VERSION = "7.8.0"
|
21
21
|
end
|
22
22
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|