elastic-transport 8.2.3 → 8.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f666d1e77cc7d01dcb75db01ae517ee1645e6630b02c32f7052f79a4c77de48
4
- data.tar.gz: 4a6af2555238d92045f6d22a15000d4a8666813602d5f3486d3f1f627ceecf58
3
+ metadata.gz: f216469707e9c57ce1ef8c9285504300763bc3603b95bb25d434c4d4cb584fec
4
+ data.tar.gz: 6ae9924b648db98d0a5d7d2f6770f0d3ff18a766b9f93545d11a5239dc3ae8c6
5
5
  SHA512:
6
- metadata.gz: 1e17397db6f79a278db371ec799b15ce366e160e19c13d1fbdbb7b3bad8b36c0cefa77e0b5086083faba9348f42d79f52c3cb77d4554a653ac707a0bb505d435
7
- data.tar.gz: 82ec2214beaae1a0423c09016140359e16b482fbc1c311906c96cb3cb8d2be54a1602cb6778c1fe624259fea92d2baf02932af223454eca4eba1403705813ba0
6
+ metadata.gz: d5e73feba635548e4109cf1c95c62cc1a12a04f46817e2edcc180cd54f0147ca1e200e5a7eb4278fa1a851fcde61ead7e9407b78adcdb81bec85569112733269
7
+ data.tar.gz: 666785c03ab0fc8d4f21636bc0856669c838ea546c983d8d2d9e41d20ea04e274ae3991261ddcdd101d64aef6db288c6da5c76fa5ec0e1002a61660b0e3f6dc9
@@ -1,11 +1,11 @@
1
- name: main tests
1
+ name: 8.2 tests
2
2
  on:
3
3
  push:
4
4
  branches:
5
- - main
5
+ - 8.2
6
6
  pull_request:
7
7
  branches:
8
- - main
8
+ - 8.2
9
9
  jobs:
10
10
  test:
11
11
  name: 'Main tests'
@@ -15,8 +15,8 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- ruby: [ '3.0', '3.1', '3.2', 'jruby-9.3', 'jruby-9.4' ]
19
- es_version: ['8.7-SNAPSHOT', '8.8-SNAPSHOT', '8.9-SNAPSHOT']
18
+ ruby: [ '3.0', '3.1', '3.2', '3.3', 'jruby-9.3', 'jruby-9.4' ]
19
+ es_version: ['8.11-SNAPSHOT', '8.12-SNAPSHOT']
20
20
  runs-on: ubuntu-latest
21
21
  steps:
22
22
  - uses: actions/checkout@v3
@@ -53,8 +53,8 @@ jobs:
53
53
  strategy:
54
54
  fail-fast: false
55
55
  matrix:
56
- ruby: [ '3.0', '3.1', '3.2', 'jruby-9.3' ]
57
- es_version: ['8.9-SNAPSHOT']
56
+ ruby: [ '3.0', '3.1', '3.2', '3.3', 'jruby-9.3' ]
57
+ es_version: ['8.12-SNAPSHOT']
58
58
  runs-on: ubuntu-latest
59
59
  steps:
60
60
  - uses: actions/checkout@v3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 8.2.5
2
+
3
+ Tested versions of Ruby: (MRI) 3.0, 3.1, 3.2, 3.3, JRuby 9.3 and JRuby 9.4
4
+
5
+ - Removes unneccessary `require 'base64'` found thanks to warning in Ruby 3.3. So this removes the warning too if you were using Ruby 3.3.
6
+
7
+ ## 8.2.4
8
+
9
+ Tested versions of Ruby: (MRI) 3.0, 3.1, 3.2, JRuby 9.3 and JRuby 9.4
10
+
11
+ - 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)
12
+ - 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!
13
+
1
14
  ## 8.2.3
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
@@ -26,6 +26,7 @@ group :development, :test do
26
26
  gem 'faraday-patron' unless defined? JRUBY_VERSION
27
27
  gem 'faraday-typhoeus'
28
28
  gem 'rspec'
29
+ gem 'oj' unless defined? JRUBY_VERSION
29
30
  if defined?(JRUBY_VERSION)
30
31
  gem 'pry-nav'
31
32
  else
@@ -31,6 +31,7 @@ group :development, :test do
31
31
  gem 'patron' unless defined? JRUBY_VERSION
32
32
  gem 'rspec'
33
33
  gem 'typhoeus'
34
+ gem 'oj' unless defined? JRUBY_VERSION
34
35
  if defined?(JRUBY_VERSION)
35
36
  gem 'pry-nav'
36
37
  else
@@ -15,7 +15,6 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require 'base64'
19
18
  require 'elastic/transport/meta_header'
20
19
 
21
20
  module Elastic
@@ -15,8 +15,6 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require 'base64'
19
-
20
18
  module Elastic
21
19
  module Transport
22
20
  # Methods for the Elastic meta header used by Cloud.
@@ -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
- json = serializer.load(response.body) if response.body &&
350
- !response.body.empty? &&
351
- response.headers &&
352
- response.headers["content-type"] =~ /json/
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, @request_options[:headers])
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
- params = params.merge @request_options
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
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elastic
19
19
  module Transport
20
- VERSION = '8.2.3'.freeze
20
+ VERSION = '8.2.5'.freeze
21
21
  end
22
22
  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 'run body with preper params' do
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 'run body with preper params' do
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
@@ -83,4 +83,4 @@ def is_faraday_v2?
83
83
  Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
84
84
  end
85
85
 
86
- Minitest::Reporters.use! FixedMinitestSpecReporter.new
86
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new(print_failure_summary: true)
@@ -111,7 +111,7 @@ if JRUBY
111
111
  {
112
112
  body: '{"foo":"bar"}',
113
113
  headers: {
114
- 'Content-Type' => 'application/json',
114
+ 'Content-Type' => 'application/x-ndjson',
115
115
  'User-Agent' => @transport.send(:user_agent_header)
116
116
  }
117
117
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.2.3
4
+ version: 8.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-31 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -337,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
337
  - !ruby/object:Gem::Version
338
338
  version: '0'
339
339
  requirements: []
340
- rubygems_version: 3.4.13
340
+ rubygems_version: 3.5.3
341
341
  signing_key:
342
342
  specification_version: 4
343
343
  summary: Low level Ruby client for Elastic services.