elasticsearch-transport 7.11.0.pre.1 → 7.13.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e364f5d86474b878377249e59488749009a24682da9d35e3eaeb430a0c9d9d4
4
- data.tar.gz: 9952aede93dd570e563acef81038e9423793f4e0682b9916d5155fa37edb0792
3
+ metadata.gz: 2170038c55227e1ebc05cd17dd055ec0c8bd30b4f3cf7e2fb60ff527c768d693
4
+ data.tar.gz: 7ab94a823a1e57348d6b4ef0b80d84cb958964cdd8ae8cd9a6464ca9fa477621
5
5
  SHA512:
6
- metadata.gz: be3c7ecd096850addb44e502f471ae2e88e43e3ee93dc342eb4b32b36eb994d66131e35f6458cec5026a02e7edd25e71d058efaa5a675fdacfe38c567a478a7f
7
- data.tar.gz: 9ed532c04edc174e1eb903bb116add80f946f1610360a0294bed09d6d3f3b26444432745c67431e3611d3c478434e5afb18db9271450854c3255ef67e049e506
6
+ metadata.gz: f34f54dbfee4ee6f8a4706d9e9634fa38fe96ceee74651b774fa243fe37f65b29608acfcc217bc10843a65c90daca17aaa6b5f8e7b21f1d9a77d0d87c43e04d0
7
+ data.tar.gz: b1a5ce57f77c59f98a968bf22d79a182c14db2fb27bedf636d07602f6da384dc11d6b111ebd3967cb18c1481e8d4298715a0a45b66ad61d55a91e666accc0f4a
@@ -16,6 +16,7 @@
16
16
  # under the License.
17
17
 
18
18
  require 'base64'
19
+ require 'elasticsearch/transport/meta_header'
19
20
 
20
21
  module Elasticsearch
21
22
  module Transport
@@ -25,6 +26,7 @@ module Elasticsearch
25
26
  # See {file:README.md README} for usage and code examples.
26
27
  #
27
28
  class Client
29
+ include MetaHeader
28
30
  DEFAULT_TRANSPORT_CLASS = Transport::HTTP::Faraday
29
31
 
30
32
  DEFAULT_LOGGER = lambda do
@@ -143,14 +145,15 @@ module Elasticsearch
143
145
  @options[:http] ||= {}
144
146
 
145
147
  set_api_key if (@api_key = @arguments[:api_key])
148
+ set_compatibility_header if ENV['ELASTIC_CLIENT_APIVERSIONING']
146
149
 
147
150
  @seeds = extract_cloud_creds(@arguments)
148
151
  @seeds ||= __extract_hosts(@arguments[:hosts] ||
149
- @arguments[:host] ||
150
- @arguments[:url] ||
151
- @arguments[:urls] ||
152
- ENV['ELASTICSEARCH_URL'] ||
153
- DEFAULT_HOST)
152
+ @arguments[:host] ||
153
+ @arguments[:url] ||
154
+ @arguments[:urls] ||
155
+ ENV['ELASTICSEARCH_URL'] ||
156
+ DEFAULT_HOST)
154
157
 
155
158
  @send_get_body_as = @arguments[:send_get_body_as] || 'GET'
156
159
  @opaque_id_prefix = @arguments[:opaque_id_prefix] || nil
@@ -165,13 +168,13 @@ module Elasticsearch
165
168
  @transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
166
169
  @transport = if @transport_class == Transport::HTTP::Faraday
167
170
  @arguments[:adapter] ||= __auto_detect_adapter
168
- set_meta_header
171
+ set_meta_header # from include MetaHeader
169
172
  @transport_class.new(hosts: @seeds, options: @arguments) do |faraday|
170
173
  faraday.adapter(@arguments[:adapter])
171
174
  block&.call faraday
172
175
  end
173
176
  else
174
- set_meta_header
177
+ set_meta_header # from include MetaHeader
175
178
  @transport_class.new(hosts: @seeds, options: @arguments)
176
179
  end
177
180
  end
@@ -198,6 +201,17 @@ module Elasticsearch
198
201
  @arguments.delete(:password)
199
202
  end
200
203
 
204
+ def set_compatibility_header
205
+ return unless ['1', 'true'].include?(ENV['ELASTIC_CLIENT_APIVERSIONING'])
206
+
207
+ add_header(
208
+ {
209
+ 'Accept' => 'application/vnd.elasticsearch+json;compatible-with=7',
210
+ 'Content-Type' => 'application/vnd.elasticsearch+json; compatible-with=7'
211
+ }
212
+ )
213
+ end
214
+
201
215
  def add_header(header)
202
216
  headers = @arguments[:transport_options]&.[](:headers) || {}
203
217
  headers.merge!(header)
@@ -206,68 +220,6 @@ module Elasticsearch
206
220
  )
207
221
  end
208
222
 
209
- def set_meta_header
210
- return if @arguments[:enable_meta_header] == false
211
-
212
- service, version = meta_header_service_version
213
-
214
- meta_headers = {
215
- service.to_sym => version,
216
- rb: RUBY_VERSION,
217
- t: Elasticsearch::Transport::VERSION
218
- }
219
- meta_headers.merge!(meta_header_engine) if meta_header_engine
220
- meta_headers.merge!(meta_header_adapter) if meta_header_adapter
221
-
222
- add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
223
- end
224
-
225
- def meta_header_service_version
226
- if defined?(Elastic::META_HEADER_SERVICE_VERSION)
227
- Elastic::META_HEADER_SERVICE_VERSION
228
- elsif defined?(Elasticsearch::VERSION)
229
- ['es', Elasticsearch::VERSION]
230
- else
231
- ['es', Elasticsearch::Transport::VERSION]
232
- end
233
- end
234
-
235
- def meta_header_engine
236
- case RUBY_ENGINE
237
- when 'ruby'
238
- {}
239
- when 'jruby'
240
- { jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
241
- when 'rbx'
242
- { rbx: RUBY_VERSION }
243
- else
244
- { RUBY_ENGINE.to_sym => RUBY_VERSION }
245
- end
246
- end
247
-
248
- def meta_header_adapter
249
- if @transport_class == Transport::HTTP::Faraday
250
- {fd: Faraday::VERSION}.merge(
251
- case @arguments[:adapter]
252
- when :patron
253
- {pt: Patron::VERSION}
254
- when :net_http
255
- {nh: defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}
256
- when :typhoeus
257
- {ty: Typhoeus::VERSION}
258
- when :httpclient
259
- {hc: HTTPClient::VERSION}
260
- when :net_http_persistent
261
- {np: Net::HTTP::Persistent::VERSION}
262
- end
263
- )
264
- elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
265
- {cl: Curl::CURB_VERSION}
266
- elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
267
- {mc: Manticore::VERSION}
268
- end
269
- end
270
-
271
223
  def extract_cloud_creds(arguments)
272
224
  return unless arguments[:cloud_id] && !arguments[:cloud_id].empty?
273
225
 
@@ -0,0 +1,135 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'base64'
19
+
20
+ module Elasticsearch
21
+ module Transport
22
+ # Methods for the Elastic meta header used by Cloud.
23
+ # X-Elastic-Client-Meta HTTP header which is used by Elastic Cloud and can be disabled when
24
+ # instantiating the Client with the :enable_meta_header parameter set to `false`.
25
+ #
26
+ module MetaHeader
27
+ def set_meta_header
28
+ return if @arguments[:enable_meta_header] == false
29
+
30
+ service, version = meta_header_service_version
31
+
32
+ meta_headers = {
33
+ service.to_sym => version,
34
+ rb: RUBY_VERSION,
35
+ t: Elasticsearch::Transport::VERSION
36
+ }
37
+ meta_headers.merge!(meta_header_engine) if meta_header_engine
38
+ meta_headers.merge!(meta_header_adapter) if meta_header_adapter
39
+
40
+ add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
41
+ end
42
+
43
+ def meta_header_service_version
44
+ if enterprise_search?
45
+ Elastic::ENTERPRISE_SERVICE_VERSION
46
+ elsif elasticsearch?
47
+ Elastic::ELASTICSEARCH_SERVICE_VERSION
48
+ elsif defined?(Elasticsearch::VERSION)
49
+ [:es, client_meta_version(Elasticsearch::VERSION)]
50
+ else
51
+ [:es, client_meta_version(Elasticsearch::Transport::VERSION)]
52
+ end
53
+ end
54
+
55
+ def enterprise_search?
56
+ defined?(Elastic::ENTERPRISE_SERVICE_VERSION) &&
57
+ called_from?('enterprise-search-ruby')
58
+ end
59
+
60
+ def elasticsearch?
61
+ defined?(Elastic::ELASTICSEARCH_SERVICE_VERSION) &&
62
+ called_from?('elasticsearch')
63
+ end
64
+
65
+ def called_from?(service)
66
+ !caller.select { |c| c.match?(service) }.empty?
67
+ end
68
+
69
+ # We return the current version if it's a release, but if it's a pre/alpha/beta release we
70
+ # return <VERSION_NUMBER>p
71
+ #
72
+ def client_meta_version(version)
73
+ regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
74
+ match = version.match(regexp)
75
+ return "#{match[1]}p" if (match[2])
76
+
77
+ version
78
+ end
79
+
80
+ def meta_header_engine
81
+ case RUBY_ENGINE
82
+ when 'ruby'
83
+ {}
84
+ when 'jruby'
85
+ { jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
86
+ when 'rbx'
87
+ { rbx: RUBY_VERSION }
88
+ else
89
+ { RUBY_ENGINE.to_sym => RUBY_VERSION }
90
+ end
91
+ end
92
+
93
+ # This function tries to define the version for the Faraday adapter. If it hasn't been loaded
94
+ # by the time we're calling this method, it's going to report the adapter (if we know it) but
95
+ # return 0 as the version. It won't report anything when using a custom adapter we don't
96
+ # identify.
97
+ #
98
+ # Returns a Hash<adapter_alias, version>
99
+ #
100
+ def meta_header_adapter
101
+ if @transport_class == Transport::HTTP::Faraday
102
+ version = '0'
103
+ adapter_version = case @arguments[:adapter]
104
+ when :patron
105
+ version = Patron::VERSION if defined?(::Patron::VERSION)
106
+ {pt: version}
107
+ when :net_http
108
+ version = if defined?(Net::HTTP::VERSION)
109
+ Net::HTTP::VERSION
110
+ elsif defined?(Net::HTTP::HTTPVersion)
111
+ Net::HTTP::HTTPVersion
112
+ end
113
+ {nh: version}
114
+ when :typhoeus
115
+ version = Typhoeus::VERSION if defined?(::Typhoeus::VERSION)
116
+ {ty: version}
117
+ when :httpclient
118
+ version = HTTPClient::VERSION if defined?(HTTPClient::VERSION)
119
+ {hc: version}
120
+ when :net_http_persistent
121
+ version = Net::HTTP::Persistent::VERSION if defined?(Net::HTTP::Persistent::VERSION)
122
+ {np: version}
123
+ else
124
+ {}
125
+ end
126
+ {fd: Faraday::VERSION}.merge(adapter_version)
127
+ elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
128
+ {cl: Curl::CURB_VERSION}
129
+ elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
130
+ {mc: Manticore::VERSION}
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -33,9 +33,17 @@ 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, opts={})
36
+ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
37
37
  super do |connection, url|
38
- headers = headers || connection.connection.headers
38
+ headers = if connection.connection.headers
39
+ if !headers.nil?
40
+ connection.connection.headers.merge(headers)
41
+ else
42
+ connection.connection.headers
43
+ end
44
+ else
45
+ headers
46
+ end
39
47
 
40
48
  response = connection.connection.run_request(method.downcase.to_sym,
41
49
  url,
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Transport
20
- VERSION = '7.11.0.pre.1'.freeze
20
+ VERSION = '7.13.0.pre'.freeze
21
21
  end
22
22
  end
@@ -266,7 +266,7 @@ describe Elasticsearch::Transport::Client do
266
266
  it 'uses Faraday with the adapter' do
267
267
  expect(adapter).to eq Faraday::Adapter::Typhoeus
268
268
  end
269
- end
269
+ end unless jruby?
270
270
 
271
271
  context 'when the adapter is specified as a string key' do
272
272
  let(:adapter) do
@@ -1423,11 +1423,51 @@ describe Elasticsearch::Transport::Client do
1423
1423
  allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
1424
1424
  expect { client.search(opaque_id: 'opaque_id') }.not_to raise_error
1425
1425
  expect(client).to have_received(:perform_request)
1426
- .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {})
1426
+ .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {})
1427
1427
  end
1428
1428
  end
1429
1429
  end
1430
1430
 
1431
+ context 'when using the API Compatibility Header' do
1432
+ it 'sets the API compatibility headers' do
1433
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'true'
1434
+ client = described_class.new(host: hosts)
1435
+ headers = client.transport.connections.first.connection.headers
1436
+
1437
+ expect(headers['Content-Type']).to eq('application/vnd.elasticsearch+json; compatible-with=7')
1438
+ expect(headers['Accept']).to eq('application/vnd.elasticsearch+json;compatible-with=7')
1439
+
1440
+ response = client.perform_request('GET', '/')
1441
+ expect(response.headers['content-type']).to eq('application/json; charset=UTF-8')
1442
+
1443
+ ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
1444
+ end
1445
+
1446
+ it 'does not use API compatibility headers' do
1447
+ val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
1448
+ client = described_class.new(host: hosts)
1449
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1450
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
1451
+ end
1452
+
1453
+ it 'does not use API compatibility headers when it is set to unsupported values' do
1454
+ val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
1455
+
1456
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'test'
1457
+ client = described_class.new(host: hosts)
1458
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1459
+
1460
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'false'
1461
+ client = described_class.new(host: hosts)
1462
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1463
+
1464
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = '3'
1465
+ client = described_class.new(host: hosts)
1466
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1467
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
1468
+ end
1469
+ end
1470
+
1431
1471
  context 'when Elasticsearch response includes a warning header' do
1432
1472
  let(:client) do
1433
1473
  Elasticsearch::Transport::Client.new(hosts: hosts)
@@ -1462,7 +1502,28 @@ describe Elasticsearch::Transport::Client do
1462
1502
  allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
1463
1503
  expect { client.search(headers: headers) }.not_to raise_error
1464
1504
  expect(client).to have_received(:perform_request)
1465
- .with('GET', '_search', {}, nil, headers)
1505
+ .with('GET', '_search', {}, nil, headers)
1506
+ end
1507
+ end
1508
+
1509
+ context 'when a header is set on an endpoint request and on initialization' do
1510
+ let!(:client) do
1511
+ described_class.new(
1512
+ host: hosts,
1513
+ transport_options: { headers: instance_headers }
1514
+ )
1515
+ end
1516
+ let(:instance_headers) { { set_in_instantiation: 'header value' } }
1517
+ let(:param_headers) {{'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value'}}
1518
+
1519
+ it 'performs the request with the header' do
1520
+ expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
1521
+
1522
+ expect_any_instance_of(Faraday::Connection)
1523
+ .to receive(:run_request)
1524
+ .with(:get, "http://#{hosts[0]}/_search", nil, expected_headers) { OpenStruct.new(body: '')}
1525
+
1526
+ client.search(headers: param_headers)
1466
1527
  end
1467
1528
  end
1468
1529
  end
@@ -1755,7 +1816,7 @@ describe Elasticsearch::Transport::Client do
1755
1816
  it 'preserves the other headers' do
1756
1817
  expect(client.transport.connections[0].connection.headers['User-Agent'])
1757
1818
  end
1758
- end
1819
+ end unless jruby?
1759
1820
  end
1760
1821
  end
1761
1822
 
@@ -20,17 +20,36 @@ require 'spec_helper'
20
20
  describe Elasticsearch::Transport::Client do
21
21
  context 'meta-header' do
22
22
  let(:subject) { client.transport.connections.first.connection.headers }
23
+ let(:client) { described_class.new }
23
24
  let(:regexp) { /^[a-z]{1,}=[a-z0-9.\-]{1,}(?:,[a-z]{1,}=[a-z0-9._\-]+)*$/ }
24
25
  let(:adapter) { :net_http }
25
26
  let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
26
27
  let(:meta_header) do
27
28
  if jruby?
28
- "es=#{Elasticsearch::VERSION},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
29
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
29
30
  else
30
- "es=#{Elasticsearch::VERSION},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
31
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
31
32
  end
32
33
  end
33
34
 
35
+ context 'client_meta_version' do
36
+ let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
37
+
38
+ it 'converts the version to X.X.Xp' do
39
+ expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
40
+ expect(client.send(:client_meta_version, '7.11.0.pre.1')).to eq('7.11.0p')
41
+ expect(client.send(:client_meta_version, '8.1.0-beta')).to eq('8.1.0p')
42
+ expect(client.send(:client_meta_version, '8.0.0.beta.2')).to eq('8.0.0p')
43
+ expect(client.send(:client_meta_version, '12.16.4.pre')).to eq('12.16.4p')
44
+ end
45
+ end
46
+
47
+ # We are testing this method in the previous block, so now using it inside the test to make the
48
+ # Elasticsearch version in the meta header string dynamic
49
+ def meta_version
50
+ client.send(:client_meta_version, Elasticsearch::VERSION)
51
+ end
52
+
34
53
  context 'single use of meta header' do
35
54
  let(:client) do
36
55
  described_class.new(adapter: adapter).tap do |klient|
@@ -78,9 +97,9 @@ describe Elasticsearch::Transport::Client do
78
97
  context 'adapters' do
79
98
  let(:meta_header) do
80
99
  if jruby?
81
- "es=#{Elasticsearch::VERSION},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
100
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
82
101
  else
83
- "es=#{Elasticsearch::VERSION},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
102
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
84
103
  end
85
104
  end
86
105
  let(:client) { described_class.new(adapter: adapter) }
@@ -89,6 +108,14 @@ describe Elasticsearch::Transport::Client do
89
108
  context 'using net/http/persistent' do
90
109
  let(:adapter) { :net_http_persistent }
91
110
 
111
+ it 'sets adapter in the meta header version to 0 when not loaded' do
112
+ fork {
113
+ expect(headers['x-elastic-client-meta']).to match(regexp)
114
+ meta = "#{meta_header},np=0"
115
+ expect(headers).to include('x-elastic-client-meta' => meta)
116
+ }
117
+ end unless jruby?
118
+
92
119
  it 'sets adapter in the meta header' do
93
120
  require 'net/http/persistent'
94
121
  expect(headers['x-elastic-client-meta']).to match(regexp)
@@ -100,6 +127,14 @@ describe Elasticsearch::Transport::Client do
100
127
  context 'using httpclient' do
101
128
  let(:adapter) { :httpclient }
102
129
 
130
+ it 'sets adapter in the meta header version to 0 when not loaded' do
131
+ fork {
132
+ expect(headers['x-elastic-client-meta']).to match(regexp)
133
+ meta = "#{meta_header},hc=0"
134
+ expect(headers).to include('x-elastic-client-meta' => meta)
135
+ }
136
+ end unless jruby?
137
+
103
138
  it 'sets adapter in the meta header' do
104
139
  require 'httpclient'
105
140
  expect(headers['x-elastic-client-meta']).to match(regexp)
@@ -111,6 +146,14 @@ describe Elasticsearch::Transport::Client do
111
146
  context 'using typhoeus' do
112
147
  let(:adapter) { :typhoeus }
113
148
 
149
+ it 'sets adapter in the meta header version to 0 when not loaded' do
150
+ fork {
151
+ expect(headers['x-elastic-client-meta']).to match(regexp)
152
+ meta = "#{meta_header},ty=0"
153
+ expect(headers).to include('x-elastic-client-meta' => meta)
154
+ }
155
+ end unless jruby?
156
+
114
157
  it 'sets adapter in the meta header' do
115
158
  require 'typhoeus'
116
159
  expect(headers['x-elastic-client-meta']).to match(regexp)
@@ -119,9 +162,19 @@ describe Elasticsearch::Transport::Client do
119
162
  end
120
163
  end
121
164
 
122
- unless defined?(JRUBY_VERSION)
165
+ unless jruby?
123
166
  let(:adapter) { :patron }
124
167
 
168
+ context 'using patron without requiring it' do
169
+ it 'sets adapter in the meta header version to 0 when not loaded' do
170
+ fork {
171
+ expect(headers['x-elastic-client-meta']).to match(regexp)
172
+ meta = "#{meta_header},pt=0"
173
+ expect(headers).to include('x-elastic-client-meta' => meta)
174
+ }
175
+ end
176
+ end
177
+
125
178
  context 'using patron' do
126
179
  it 'sets adapter in the meta header' do
127
180
  require 'patron'
@@ -131,6 +184,23 @@ describe Elasticsearch::Transport::Client do
131
184
  end
132
185
  end
133
186
  end
187
+
188
+ context 'using other' do
189
+ let(:adapter) { :some_other_adapter }
190
+
191
+ it 'sets adapter in the meta header without requiring' do
192
+ Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
193
+ expect(headers['x-elastic-client-meta']).to match(regexp)
194
+ expect(headers).to include('x-elastic-client-meta' => meta_header)
195
+ end
196
+
197
+ it 'sets adapter in the meta header' do
198
+ require 'net/http/persistent'
199
+ Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
200
+ expect(headers['x-elastic-client-meta']).to match(regexp)
201
+ expect(headers).to include('x-elastic-client-meta' => meta_header)
202
+ end
203
+ end
134
204
  end
135
205
 
136
206
  if defined?(JRUBY_VERSION)
@@ -167,9 +237,9 @@ describe Elasticsearch::Transport::Client do
167
237
  let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
168
238
  let(:meta_header) do
169
239
  if jruby?
170
- "es=#{Elasticsearch::VERSION},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
240
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
171
241
  else
172
- "es=#{Elasticsearch::VERSION},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
242
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
173
243
  end
174
244
  end
175
245
 
@@ -181,15 +251,7 @@ describe Elasticsearch::Transport::Client do
181
251
 
182
252
  context 'when using a different service version' do
183
253
  before do
184
- module Elastic
185
- META_HEADER_SERVICE_VERSION = [:ent, '8.0.0']
186
- end
187
- end
188
-
189
- after do
190
- module Elastic
191
- META_HEADER_SERVICE_VERSION = [:es, Elasticsearch::VERSION]
192
- end
254
+ stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
193
255
  end
194
256
 
195
257
  let(:client) { Elasticsearch::Client.new }
@@ -32,7 +32,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
32
32
  begin; Object.send(:remove_const, :Patron); rescue NameError; end
33
33
  end
34
34
 
35
- should "allow to customize the Faraday adapter" do
35
+ should "allow to customize the Faraday adapter to Typhoeus" do
36
36
  require 'typhoeus'
37
37
  require 'typhoeus/adapters/faraday'
38
38
 
@@ -42,6 +42,19 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
42
42
  f.adapter :typhoeus
43
43
  end
44
44
 
45
+ client = Elasticsearch::Transport::Client.new transport: transport
46
+ client.perform_request 'GET', ''
47
+ end unless jruby?
48
+
49
+ should "allow to customize the Faraday adapter to NetHttpPersistent" do
50
+ require 'net/http/persistent'
51
+
52
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
53
+ :hosts => [ { host: @host, port: @port } ] do |f|
54
+ f.response :logger
55
+ f.adapter :net_http_persistent
56
+ end
57
+
45
58
  client = Elasticsearch::Transport::Client.new transport: transport
46
59
  client.perform_request 'GET', ''
47
60
  end
@@ -64,8 +64,8 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites
64
64
 
65
65
  should "have a string representation" do
66
66
  c = Connection.new :host => 'x'
67
- assert_match /host: x/, c.to_s
68
- assert_match /alive/, c.to_s
67
+ assert_match(/host: x/, c.to_s)
68
+ assert_match(/alive/, c.to_s)
69
69
  end
70
70
 
71
71
  should "not be dead by default" do
@@ -429,7 +429,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
429
429
  @transport.stubs(:get_connection).returns(fake_connection)
430
430
 
431
431
  @transport.logger.expects(:info).with do |message|
432
- assert_match /http:\/\/user:\*{1,15}@localhost\:9200/, message
432
+ assert_match(/http:\/\/user:\*{1,15}@localhost\:9200/, message)
433
433
  true
434
434
  end
435
435
 
@@ -149,7 +149,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
149
149
 
150
150
  transport.connections.first.connection.expects(:run_request).
151
151
  with do |method, url, params, body|
152
- assert_match /\?format=yaml/, url
152
+ assert_match(/\?format=yaml/, url)
153
153
  true
154
154
  end.
155
155
  returns(stub_everything)
@@ -167,7 +167,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
167
167
 
168
168
  transport.connections.first.connection.expects(:run_request).
169
169
  with do |method, url, params, body|
170
- assert_match /\?format=json/, url
170
+ assert_match(/\?format=json/, url)
171
171
  true
172
172
  end.
173
173
  returns(stub_everything)
@@ -145,8 +145,8 @@ else
145
145
  transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
146
146
  transport.connections.first.connection
147
147
  .expects(:get)
148
- .with do |host, options|
149
- assert_equal 'myapp-0.0', options[:headers]['User-Agent']
148
+ .with do |host, _options|
149
+ assert_equal 'myapp-0.0', _options[:headers]['User-Agent']
150
150
  true
151
151
  end
152
152
  .returns(stub_everything)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.11.0.pre.1
4
+ version: 7.13.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-11 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -373,6 +373,7 @@ files:
373
373
  - lib/elasticsearch-transport.rb
374
374
  - lib/elasticsearch/transport.rb
375
375
  - lib/elasticsearch/transport/client.rb
376
+ - lib/elasticsearch/transport/meta_header.rb
376
377
  - lib/elasticsearch/transport/redacted.rb
377
378
  - lib/elasticsearch/transport/transport/base.rb
378
379
  - lib/elasticsearch/transport/transport/connections/collection.rb
@@ -428,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
428
429
  - !ruby/object:Gem::Version
429
430
  version: 1.3.1
430
431
  requirements: []
431
- rubygems_version: 3.1.4
432
+ rubygems_version: 3.2.16
432
433
  signing_key:
433
434
  specification_version: 4
434
435
  summary: Ruby client for Elasticsearch.