elasticsearch-transport 7.11.0 → 7.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elasticsearch/transport/client.rb +21 -77
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/client_spec.rb +42 -2
- data/spec/elasticsearch/transport/meta_header_spec.rb +54 -3
- data/test/integration/transport_test.rb +14 -1
- data/test/unit/connection_test.rb +2 -2
- data/test/unit/transport_base_test.rb +1 -1
- data/test/unit/transport_faraday_test.rb +2 -2
- data/test/unit/transport_manticore_test.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7450e65878dd55088bede46fce476da9741626497de99f0b529c69ff31b244eb
|
4
|
+
data.tar.gz: a53fc0c6ca93ec006f31adce15c69e199c58d4aa70dc0925ad979958eca2560e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e77be4dc4155782e358d20fc0eed4c6d164aad4e1c7fa93aec4a4e61b54bfb3674f1c363ffd6382b88423e455b1739fe0fd67fdf79024a60fc96e7f84296bf03
|
7
|
+
data.tar.gz: 46efad58b4e8464ebc8fee9fe74bb1438c5f9bf32de8c3cfe70d96611b66e1b478582bd6dfea33d5868af1fdd5cb8b230bcb8f837970df362036f4a015a2f2b6
|
@@ -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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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,76 +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, client_meta_version(Elasticsearch::VERSION)]
|
230
|
-
else
|
231
|
-
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def client_meta_version(version)
|
236
|
-
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
237
|
-
match = version.match(regexp)
|
238
|
-
return "#{match[1]}p" if (match[2])
|
239
|
-
|
240
|
-
version
|
241
|
-
end
|
242
|
-
|
243
|
-
def meta_header_engine
|
244
|
-
case RUBY_ENGINE
|
245
|
-
when 'ruby'
|
246
|
-
{}
|
247
|
-
when 'jruby'
|
248
|
-
{ jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
|
249
|
-
when 'rbx'
|
250
|
-
{ rbx: RUBY_VERSION }
|
251
|
-
else
|
252
|
-
{ RUBY_ENGINE.to_sym => RUBY_VERSION }
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def meta_header_adapter
|
257
|
-
if @transport_class == Transport::HTTP::Faraday
|
258
|
-
{fd: Faraday::VERSION}.merge(
|
259
|
-
case @arguments[:adapter]
|
260
|
-
when :patron
|
261
|
-
{pt: Patron::VERSION}
|
262
|
-
when :net_http
|
263
|
-
{nh: defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}
|
264
|
-
when :typhoeus
|
265
|
-
{ty: Typhoeus::VERSION}
|
266
|
-
when :httpclient
|
267
|
-
{hc: HTTPClient::VERSION}
|
268
|
-
when :net_http_persistent
|
269
|
-
{np: Net::HTTP::Persistent::VERSION}
|
270
|
-
end
|
271
|
-
)
|
272
|
-
elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
|
273
|
-
{cl: Curl::CURB_VERSION}
|
274
|
-
elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
|
275
|
-
{mc: Manticore::VERSION}
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
223
|
def extract_cloud_creds(arguments)
|
280
224
|
return unless arguments[:cloud_id] && !arguments[:cloud_id].empty?
|
281
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
|
@@ -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
|
@@ -1428,6 +1428,46 @@ describe Elasticsearch::Transport::Client do
|
|
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)
|
@@ -1776,7 +1816,7 @@ describe Elasticsearch::Transport::Client do
|
|
1776
1816
|
it 'preserves the other headers' do
|
1777
1817
|
expect(client.transport.connections[0].connection.headers['User-Agent'])
|
1778
1818
|
end
|
1779
|
-
end
|
1819
|
+
end unless jruby?
|
1780
1820
|
end
|
1781
1821
|
end
|
1782
1822
|
|
@@ -32,7 +32,7 @@ describe Elasticsearch::Transport::Client do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context '
|
35
|
+
context 'client_meta_version' do
|
36
36
|
let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
|
37
37
|
|
38
38
|
it 'converts the version to X.X.Xp' do
|
@@ -108,6 +108,14 @@ describe Elasticsearch::Transport::Client do
|
|
108
108
|
context 'using net/http/persistent' do
|
109
109
|
let(:adapter) { :net_http_persistent }
|
110
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
|
+
|
111
119
|
it 'sets adapter in the meta header' do
|
112
120
|
require 'net/http/persistent'
|
113
121
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -119,6 +127,14 @@ describe Elasticsearch::Transport::Client do
|
|
119
127
|
context 'using httpclient' do
|
120
128
|
let(:adapter) { :httpclient }
|
121
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
|
+
|
122
138
|
it 'sets adapter in the meta header' do
|
123
139
|
require 'httpclient'
|
124
140
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -130,6 +146,14 @@ describe Elasticsearch::Transport::Client do
|
|
130
146
|
context 'using typhoeus' do
|
131
147
|
let(:adapter) { :typhoeus }
|
132
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
|
+
|
133
157
|
it 'sets adapter in the meta header' do
|
134
158
|
require 'typhoeus'
|
135
159
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -138,9 +162,19 @@ describe Elasticsearch::Transport::Client do
|
|
138
162
|
end
|
139
163
|
end
|
140
164
|
|
141
|
-
unless
|
165
|
+
unless jruby?
|
142
166
|
let(:adapter) { :patron }
|
143
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
|
+
|
144
178
|
context 'using patron' do
|
145
179
|
it 'sets adapter in the meta header' do
|
146
180
|
require 'patron'
|
@@ -150,6 +184,23 @@ describe Elasticsearch::Transport::Client do
|
|
150
184
|
end
|
151
185
|
end
|
152
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
|
153
204
|
end
|
154
205
|
|
155
206
|
if defined?(JRUBY_VERSION)
|
@@ -200,7 +251,7 @@ describe Elasticsearch::Transport::Client do
|
|
200
251
|
|
201
252
|
context 'when using a different service version' do
|
202
253
|
before do
|
203
|
-
stub_const(
|
254
|
+
stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
|
204
255
|
end
|
205
256
|
|
206
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
|
68
|
-
assert_match
|
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
|
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
|
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
|
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,
|
149
|
-
assert_equal 'myapp-0.0',
|
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.
|
4
|
+
version: 7.13.0
|
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-
|
11
|
+
date: 2021-05-25 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: '0'
|
430
431
|
requirements: []
|
431
|
-
rubygems_version: 3.
|
432
|
+
rubygems_version: 3.2.16
|
432
433
|
signing_key:
|
433
434
|
specification_version: 4
|
434
435
|
summary: Ruby client for Elasticsearch.
|