elastic-transport 8.2.2 → 8.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/license.yml +1 -1
- data/.github/workflows/tests.yml +2 -2
- data/CHANGELOG.md +13 -0
- data/Gemfile +1 -0
- data/Gemfile-faraday1.gemfile +1 -0
- data/README.md +2 -1
- data/elastic-transport.gemspec +2 -2
- data/lib/elastic/transport/transport/base.rb +11 -4
- data/lib/elastic/transport/transport/http/manticore.rb +8 -3
- data/lib/elastic/transport/transport/response.rb +2 -3
- data/lib/elastic/transport/version.rb +1 -1
- data/spec/elastic/transport/client_spec.rb +43 -0
- data/spec/elastic/transport/http/manticore_spec.rb +20 -2
- data/test/test_helper.rb +1 -1
- data/test/unit/transport_manticore_test.rb +1 -1
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79d083cf524ffa5874b8e52be857908cf520c551040d40a15730b3e6cd20507d
|
4
|
+
data.tar.gz: 87338ca40ec28d77034f902e67b324bccf70d0e0c871c5e60547291079f2b018
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1b4d5fbbb1e173d78ec57b4cb2821d852c2bcd899e17253ec6a14e23794ff0143d2184dbada48c897b2e558192163631eaf208e77a879afe0868e7b57aca1ed
|
7
|
+
data.tar.gz: 6e093adf8f2a670f4ed62b21bb60387af00ea47bfc16b66a9da8eba02e891982f54c6a0467c329c4079b202b1425728bf882e87af7494d8a720fd883b1730021
|
data/.github/workflows/tests.yml
CHANGED
@@ -19,7 +19,7 @@ jobs:
|
|
19
19
|
es_version: ['8.7-SNAPSHOT', '8.8-SNAPSHOT', '8.9-SNAPSHOT']
|
20
20
|
runs-on: ubuntu-latest
|
21
21
|
steps:
|
22
|
-
- uses: actions/checkout@
|
22
|
+
- uses: actions/checkout@v3
|
23
23
|
- name: Increase system limits
|
24
24
|
run: |
|
25
25
|
sudo swapoff -a
|
@@ -57,7 +57,7 @@ jobs:
|
|
57
57
|
es_version: ['8.9-SNAPSHOT']
|
58
58
|
runs-on: ubuntu-latest
|
59
59
|
steps:
|
60
|
-
- uses: actions/checkout@
|
60
|
+
- uses: actions/checkout@v3
|
61
61
|
- name: Increase system limits
|
62
62
|
run: |
|
63
63
|
sudo swapoff -a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 8.2.4
|
2
|
+
|
3
|
+
Tested versions of Ruby: (MRI) 3.0, 3.1, 3.2, JRuby 9.3 and JRuby 9.4
|
4
|
+
|
5
|
+
- Fixes [#66](https://github.com/elastic/elastic-transport-ruby/issues/66) - Manticore transport unable to send custom headers with perform_request [Pull Request](https://github.com/elastic/elastic-transport-ruby/pull/69)
|
6
|
+
- Fixes [#67](https://github.com/elastic/elastic-transport-ruby/issues/67) - Float with many digits automatically becomes BigDecimal when using Oj. [Pull Request](https://github.com/elastic/elastic-transport-ruby/pull/68), thank you @kyoshidajp!
|
7
|
+
|
8
|
+
## 8.2.3
|
9
|
+
|
10
|
+
Tested versions of Ruby: (MRI) 3.0, 3.1, 3.2, JRuby 9.3 and JRuby 9.4
|
11
|
+
|
12
|
+
- Fixes enforcing UTF-8 in Response body, causing an error when the string is frozen, particularly when using webmock. [issue #63](https://github.com/elastic/elastic-transport-ruby/issues/63)
|
13
|
+
|
1
14
|
## 8.2.2
|
2
15
|
|
3
16
|
Tested versions of Ruby: (MRI) 3.0, 3.1, 3.2, JRuby 9.3 and JRuby 9.4
|
data/Gemfile
CHANGED
data/Gemfile-faraday1.gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Elastic Transport
|
2
|
+
[![8.1 tests](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml/badge.svg?branch=8.1)](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml)
|
2
3
|
[![Run tests](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml)
|
3
4
|
|
4
5
|
This gem provides a low-level Ruby client for connecting to an [Elastic](http://elastic.co) cluster. It powers both the [Elasticsearch client](https://github.com/elasticsearch/elasticsearch-ruby/) and the [Elastic Enterprise Search](https://github.com/elastic/enterprise-search-ruby/) client.
|
@@ -15,7 +16,7 @@ response = client.perform_request('GET', '_cluster/health')
|
|
15
16
|
|
16
17
|
**Refer to [the official documentation on Elastic Transport](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/transport.html).**
|
17
18
|
|
18
|
-
**Refer to [Advanced Configuration](https://
|
19
|
+
**Refer to [Advanced Configuration](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/advanced-config.html) to read about more configuration options.**
|
19
20
|
|
20
21
|
## Compatibility
|
21
22
|
|
data/elastic-transport.gemspec
CHANGED
@@ -23,8 +23,8 @@ require 'elastic/transport/version'
|
|
23
23
|
Gem::Specification.new do |s|
|
24
24
|
s.name = "elastic-transport"
|
25
25
|
s.version = Elastic::Transport::VERSION
|
26
|
-
s.authors = ['
|
27
|
-
s.email = ['
|
26
|
+
s.authors = ['Elastic Client Library Maintainers']
|
27
|
+
s.email = ['client-libs@elastic.co']
|
28
28
|
s.summary = 'Low level Ruby client for Elastic services.'
|
29
29
|
s.homepage = 'https://github.com/elastic/elastic-transport-ruby'
|
30
30
|
s.license = 'Apache-2.0'
|
@@ -346,10 +346,17 @@ module Elastic
|
|
346
346
|
__raise_transport_error response unless ignore.include?(response.status.to_i)
|
347
347
|
end
|
348
348
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
349
|
+
if response.body &&
|
350
|
+
!response.body.empty? &&
|
351
|
+
response.headers &&
|
352
|
+
response.headers["content-type"] =~ /json/
|
353
|
+
|
354
|
+
# Prevent Float value from automatically becoming BigDecimal when using Oj
|
355
|
+
load_options = {}
|
356
|
+
load_options[:mode] = :compat if ::MultiJson.adapter.to_s == "MultiJson::Adapters::Oj"
|
357
|
+
|
358
|
+
json = serializer.load(response.body, load_options)
|
359
|
+
end
|
353
360
|
took = (json['took'] ? sprintf('%.3fs', json['took'] / 1000.0) : 'n/a') rescue 'n/a'
|
354
361
|
__log_response(method, path, params, body, url, response, json, took, duration) unless ignore.include?(response.status.to_i)
|
355
362
|
__trace(method, path, params, connection_headers(connection), body, url, response, nil, 'N/A', duration) if tracer
|
@@ -90,11 +90,10 @@ module Elastic
|
|
90
90
|
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
|
91
91
|
super do |connection, url|
|
92
92
|
body = body ? __convert_to_json(body) : nil
|
93
|
-
body, headers = compress_request(body,
|
94
|
-
|
93
|
+
body, headers = compress_request(body, parse_headers(headers))
|
95
94
|
params[:body] = body if body
|
96
95
|
params[:headers] = headers if headers
|
97
|
-
|
96
|
+
|
98
97
|
case method
|
99
98
|
when 'GET'
|
100
99
|
resp = connection.connection.get(url, params)
|
@@ -161,6 +160,12 @@ module Elastic
|
|
161
160
|
|
162
161
|
private
|
163
162
|
|
163
|
+
def parse_headers(headers)
|
164
|
+
request_headers = @request_options.fetch(:headers, {})
|
165
|
+
headers = request_headers.merge(headers || {})
|
166
|
+
headers.empty? ? nil : headers
|
167
|
+
end
|
168
|
+
|
164
169
|
def apply_headers(options)
|
165
170
|
headers = options[:headers].clone || options.dig(:transport_options, :headers).clone || {}
|
166
171
|
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
@@ -19,8 +19,7 @@ module Elastic
|
|
19
19
|
module Transport
|
20
20
|
module Transport
|
21
21
|
# Wraps the response from Elasticsearch.
|
22
|
-
# It provides `body`, `status` and `headers` methods
|
23
|
-
# access the keys directly.
|
22
|
+
# It provides `body`, `status` and `headers` methods
|
24
23
|
class Response
|
25
24
|
attr_reader :status, :body, :headers
|
26
25
|
|
@@ -29,7 +28,7 @@ module Elastic
|
|
29
28
|
# @param headers [Hash] Response headers
|
30
29
|
def initialize(status, body, headers = {})
|
31
30
|
@status, @body, @headers = status, body, headers
|
32
|
-
@body = body.force_encoding('UTF-8') if body.respond_to?(:force_encoding)
|
31
|
+
@body = body.force_encoding('UTF-8') if body.respond_to?(:force_encoding) && !body.frozen?
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -1190,6 +1190,49 @@ describe Elastic::Transport::Client do
|
|
1190
1190
|
expect(logger).to have_received(:warn).with(warning)
|
1191
1191
|
end
|
1192
1192
|
end
|
1193
|
+
|
1194
|
+
context 'when Elasticsearch response includes long precision Float' do
|
1195
|
+
let(:client) do
|
1196
|
+
Elastic::Transport::Client.new(hosts: hosts)
|
1197
|
+
end
|
1198
|
+
before do
|
1199
|
+
expect_any_instance_of(Faraday::Connection).to receive(:run_request) do
|
1200
|
+
Elastic::Transport::Transport::Response.new(200, "{\"score\":1.11111111111111111}", { 'content-type' => 'application/json; charset=UTF-8' })
|
1201
|
+
end
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
context 'when default JSON engine is used' do
|
1205
|
+
after do
|
1206
|
+
# Clear MultiJson's adapter
|
1207
|
+
::MultiJson.instance_variable_set(:@adapter, nil)
|
1208
|
+
end
|
1209
|
+
it 'returns as a Float' do
|
1210
|
+
response = client.perform_request('GET', '/')
|
1211
|
+
score = response.body['score']
|
1212
|
+
expect(score).to eq 1.11111111111111111
|
1213
|
+
expect(score.class).to eq Float
|
1214
|
+
end
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
unless defined?(JRUBY_VERSION)
|
1218
|
+
context 'when Oj is used as a JSON engine' do
|
1219
|
+
before do
|
1220
|
+
require 'oj'
|
1221
|
+
end
|
1222
|
+
after do
|
1223
|
+
# Clear MultiJson's adapter
|
1224
|
+
::MultiJson.instance_variable_set(:@adapter, nil)
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
it 'returns as a Float' do
|
1228
|
+
response = client.perform_request('GET', '/')
|
1229
|
+
score = response.body['score']
|
1230
|
+
expect(score).to eq 1.11111111111111111
|
1231
|
+
expect(score.class).to eq Float
|
1232
|
+
end
|
1233
|
+
end
|
1234
|
+
end
|
1235
|
+
end
|
1193
1236
|
end
|
1194
1237
|
|
1195
1238
|
context 'when the client connects to Elasticsearch' do
|
@@ -53,7 +53,7 @@ if defined?(JRUBY_VERSION)
|
|
53
53
|
expect(perform_request).to be_kind_of(Elastic::Transport::Transport::Response)
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
56
|
+
it 'runs body with proper params' do
|
57
57
|
expect(
|
58
58
|
client.transport.connections.first.connection
|
59
59
|
).to receive(:post).with(
|
@@ -121,7 +121,7 @@ if defined?(JRUBY_VERSION)
|
|
121
121
|
gzip.close.string
|
122
122
|
end
|
123
123
|
|
124
|
-
it '
|
124
|
+
it 'runs body with proper params' do
|
125
125
|
expect(
|
126
126
|
client.transport.connections.first.connection
|
127
127
|
).to receive(:post).with(*request_params).and_return(response)
|
@@ -141,6 +141,24 @@ if defined?(JRUBY_VERSION)
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
144
|
+
|
145
|
+
context 'headers' do
|
146
|
+
it 'sends custom headers' do
|
147
|
+
client = Elastic::Transport::Client.new(
|
148
|
+
transport_class: described_class,
|
149
|
+
transport_options: { headers: { 'Elastic-Api-Version'=>'2023-10-31' } }
|
150
|
+
)
|
151
|
+
expect(
|
152
|
+
client.transport.connections.first.connection
|
153
|
+
).to receive(:get).with(
|
154
|
+
'http://localhost:9200/',
|
155
|
+
{
|
156
|
+
headers: expected_headers.merge({ 'Elastic-Api-Version'=>'2023-10-31' })
|
157
|
+
}
|
158
|
+
).and_return(response)
|
159
|
+
client.perform_request('GET', '/', {}, nil, headers)
|
160
|
+
end
|
161
|
+
end
|
144
162
|
end
|
145
163
|
end
|
146
164
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.2.
|
4
|
+
version: 8.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Emily Stolfo
|
9
|
-
- Fernando Briano
|
7
|
+
- Elastic Client Library Maintainers
|
10
8
|
autorequire:
|
11
9
|
bindir: bin
|
12
10
|
cert_chain: []
|
13
|
-
date: 2023-
|
11
|
+
date: 2023-09-25 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: faraday
|
@@ -255,7 +253,7 @@ description: 'Low level Ruby client for Elastic. See the `elasticsearch` or `ela
|
|
255
253
|
|
256
254
|
'
|
257
255
|
email:
|
258
|
-
-
|
256
|
+
- client-libs@elastic.co
|
259
257
|
executables: []
|
260
258
|
extensions: []
|
261
259
|
extra_rdoc_files:
|
@@ -339,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
339
337
|
- !ruby/object:Gem::Version
|
340
338
|
version: '0'
|
341
339
|
requirements: []
|
342
|
-
rubygems_version: 3.4.
|
340
|
+
rubygems_version: 3.4.19
|
343
341
|
signing_key:
|
344
342
|
specification_version: 4
|
345
343
|
summary: Low level Ruby client for Elastic services.
|