elasticsearch-transport 7.17.8 → 7.17.10

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: e07e10bc048337e82efb7c1705c7758b4490b6a6306757d283d10b1648333abb
4
- data.tar.gz: 9ddf1e9eb94035f0629e16573a273730a5c9d51988677bd1f51061f30ca3697e
3
+ metadata.gz: 9e0c37098be528ebc37efec244285f3601ba8251c355195d5d64b5d3d6146b01
4
+ data.tar.gz: 7dd46af46b3ae346e4f76a6f8cae669e27964cddd8cd9e91ca4329cf34f8fb74
5
5
  SHA512:
6
- metadata.gz: f6d33245469de43ed5e854c8ec0a6370bc61d1f85cfc824fe3ce07c04708e54c0db793f2c4b672ad62acd617d5dc0de0c9264690a3b90dbf1cf112e27b4f8919
7
- data.tar.gz: 570fa8a837f985eaea2a4664f399b68e432a91bc1f362469f72cd072157ff45b9c0e2584a8a420a2fe61d284b89a78ce35234770549fbd061e6964ce91ed7df8
6
+ metadata.gz: 7c1d381899e45182eb000f45f1e014c2944741f817276424cefcbce05e26878da524ecc0c8d64c2dba3b290e755b30a7428b11fb6d65fd417528d92007418ed6
7
+ data.tar.gz: f2639368b74d2884376420cccb89e591dae6ecbfdc4632224d1f073ba34000ea54c498e5cb6256a60dda8f9a9a02a218158fbef64d62e1b6118b13b6912a2334
data/Gemfile CHANGED
@@ -29,6 +29,10 @@ if File.exist? File.expand_path('../elasticsearch/elasticsearch.gemspec', __dir_
29
29
  end
30
30
 
31
31
  group :development, :test do
32
+ gem 'faraday-httpclient'
33
+ gem 'faraday-net_http_persistent'
34
+ gem 'faraday-patron' unless defined? JRUBY_VERSION
35
+ gem 'faraday-typhoeus'
32
36
  gem 'rspec'
33
37
  if defined?(JRUBY_VERSION)
34
38
  gem 'pry-nav'
@@ -0,0 +1,47 @@
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
+ source 'https://rubygems.org'
19
+
20
+ # Usage:
21
+ #
22
+ # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
23
+ # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
24
+
25
+ gem 'faraday', '~> 1'
26
+ gemspec path: './'
27
+
28
+ if File.exist? File.expand_path('../elasticsearch-api/elasticsearch-api.gemspec', __dir__)
29
+ gem 'elasticsearch-api', path: File.expand_path('../elasticsearch-api', __dir__), require: false
30
+ end
31
+
32
+ if File.exist? File.expand_path('../elasticsearch/elasticsearch.gemspec', __dir__)
33
+ gem 'elasticsearch', path: File.expand_path('../elasticsearch', __dir__), require: false
34
+ end
35
+
36
+ group :development, :test do
37
+ gem 'httpclient'
38
+ gem 'net-http-persistent'
39
+ gem 'patron' unless defined? JRUBY_VERSION
40
+ gem 'typhoeus'
41
+ gem 'rspec'
42
+ if defined?(JRUBY_VERSION)
43
+ gem 'pry-nav'
44
+ else
45
+ gem 'pry-byebug'
46
+ end
47
+ end
data/Rakefile CHANGED
@@ -25,6 +25,15 @@ task :test => 'test:unit'
25
25
 
26
26
  require 'rake/testtask'
27
27
  require 'rspec/core/rake_task'
28
+ FARADAY1_GEMFILE = 'Gemfile-faraday1.gemfile'.freeze
29
+ GEMFILES = ['Gemfile', FARADAY1_GEMFILE].freeze
30
+
31
+ task :install do
32
+ GEMFILES.each do |gemfile|
33
+ gemfile = File.expand_path("../#{gemfile}", __FILE__)
34
+ sh "bundle install --gemfile #{gemfile}"
35
+ end
36
+ end
28
37
 
29
38
  namespace :test do
30
39
  desc 'Wait for Elasticsearch to be in a green state'
@@ -52,6 +61,7 @@ namespace :test do
52
61
  desc 'Run all tests'
53
62
  task :all do
54
63
  Rake::Task['test:unit'].invoke
64
+ Rake::Task['test:spec'].invoke
55
65
  Rake::Task['test:integration'].invoke
56
66
  end
57
67
 
@@ -60,6 +70,34 @@ namespace :test do
60
70
  test.test_files = FileList['test/profile/**/*_test.rb']
61
71
  end
62
72
 
73
+ namespace :faraday1 do
74
+ desc 'Faraday 1: Run RSpec with dependency on Faraday 1'
75
+ task :spec do
76
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} bundle exec rspec"
77
+ end
78
+
79
+ desc 'Faraday 1: Run unit tests with dependency on Faraday 1'
80
+ task :unit do
81
+ Dir.glob('./test/unit/**/**.rb').each do |test|
82
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
83
+ end
84
+ end
85
+
86
+ desc 'Faraday 1: Run integration tests with dependency on Faraday 1'
87
+ task :integration do
88
+ Dir.glob('./test/integration/**/**.rb').each do |test|
89
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
90
+ end
91
+ end
92
+
93
+ desc 'Faraday 1: Run all tests'
94
+ task :all do
95
+ Rake::Task['test:faraday1:unit'].invoke
96
+ Rake::Task['test:faraday1:spec'].invoke
97
+ Rake::Task['test:faraday1:integration'].invoke
98
+ end
99
+ end
100
+
63
101
  namespace :cluster do
64
102
  desc "Start Elasticsearch nodes for tests"
65
103
  task :start do
@@ -45,21 +45,20 @@ Gem::Specification.new do |s|
45
45
  s.required_ruby_version = '>= 2.4'
46
46
 
47
47
  s.add_dependency 'multi_json'
48
- s.add_dependency 'faraday', '~> 1'
48
+ s.add_dependency 'faraday', '>= 1', '< 3'
49
49
 
50
+ # Faraday Adapters
51
+ s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
52
+ s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
50
53
  s.add_development_dependency 'ansi'
51
54
  s.add_development_dependency 'bundler'
52
55
  s.add_development_dependency 'cane'
53
- s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
54
56
  s.add_development_dependency 'elasticsearch', ['>= 7', '< 8.0.0']
55
57
  s.add_development_dependency 'elasticsearch-extensions'
56
58
  s.add_development_dependency 'hashie'
57
- s.add_development_dependency 'httpclient'
58
- s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
59
59
  s.add_development_dependency 'minitest'
60
60
  s.add_development_dependency 'minitest-reporters'
61
61
  s.add_development_dependency 'mocha'
62
- s.add_development_dependency 'net-http-persistent'
63
62
  s.add_development_dependency 'patron' unless defined? JRUBY_VERSION
64
63
  s.add_development_dependency 'pry'
65
64
  s.add_development_dependency 'rake', '~> 13'
@@ -68,7 +67,6 @@ Gem::Specification.new do |s|
68
67
  s.add_development_dependency 'shoulda-context'
69
68
  s.add_development_dependency 'simplecov'
70
69
  s.add_development_dependency 'test-unit', '~> 2'
71
- s.add_development_dependency 'typhoeus', '~> 1.4'
72
70
  s.add_development_dependency 'yard'
73
71
 
74
72
  s.description = <<-DESC.gsub(/^ /, '')
@@ -87,14 +87,13 @@ module Elasticsearch
87
87
  # @return [Response]
88
88
  # @see Transport::Base#perform_request
89
89
  #
90
- def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
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,8 +160,14 @@ module Elasticsearch
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
- headers = options[:headers] || options.dig(:transport_options, :headers) || {}
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
167
172
  headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || find_value(@request_options[:headers], USER_AGENT_REGEX) || user_agent_header
168
173
  headers[ACCEPT_ENCODING] = GZIP if use_compression?
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Transport
20
- VERSION = '7.17.8'.freeze
20
+ VERSION = '7.17.10'.freeze
21
21
  end
22
22
  end
@@ -145,7 +145,8 @@ describe Elasticsearch::Transport::Transport::Base do
145
145
  let(:arguments) do
146
146
  {
147
147
  hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
148
- retry_on_failure: 2
148
+ retry_on_failure: 2,
149
+ adapter: :net_http
149
150
  }
150
151
  end
151
152
 
@@ -169,7 +170,8 @@ describe Elasticsearch::Transport::Transport::Base do
169
170
  let(:arguments) do
170
171
  {
171
172
  hosts: ELASTICSEARCH_HOSTS,
172
- retry_on_status: ['404']
173
+ retry_on_status: ['404'],
174
+ adapter: :net_http
173
175
  }
174
176
  end
175
177
 
@@ -234,8 +234,8 @@ describe Elasticsearch::Transport::Client do
234
234
  it 'uses Faraday NetHttp' do
235
235
  expect(adapter).to eq Faraday::Adapter::NetHttp
236
236
  end
237
- end unless jruby?
238
- end
237
+ end
238
+ end unless jruby?
239
239
 
240
240
  context 'when the adapter is patron' do
241
241
  let(:adapter) do
@@ -247,9 +247,10 @@ describe Elasticsearch::Transport::Client do
247
247
  end
248
248
 
249
249
  it 'uses Faraday with the adapter' do
250
+ require 'faraday/patron'
250
251
  expect(adapter).to eq Faraday::Adapter::Patron
251
252
  end
252
- end
253
+ end unless jruby?
253
254
 
254
255
  context 'when the adapter is typhoeus' do
255
256
  let(:adapter) do
@@ -257,6 +258,8 @@ describe Elasticsearch::Transport::Client do
257
258
  end
258
259
 
259
260
  let(:client) do
261
+ require 'faraday/typhoeus' if is_faraday_v2?
262
+
260
263
  described_class.new(adapter: :typhoeus, enable_meta_header: false)
261
264
  end
262
265
 
@@ -277,7 +280,7 @@ describe Elasticsearch::Transport::Client do
277
280
  it 'uses Faraday with the adapter' do
278
281
  expect(adapter).to eq Faraday::Adapter::Patron
279
282
  end
280
- end
283
+ end unless jruby?
281
284
 
282
285
  context 'when the adapter can be detected', unless: jruby? do
283
286
 
@@ -319,7 +322,7 @@ describe Elasticsearch::Transport::Client do
319
322
  it 'sets the logger' do
320
323
  expect(handlers).to include(Faraday::Response::Logger)
321
324
  end
322
- end
325
+ end unless jruby?
323
326
  end
324
327
 
325
328
  context 'when cloud credentials are provided' do
@@ -1587,6 +1590,8 @@ describe Elasticsearch::Transport::Client do
1587
1590
  end
1588
1591
 
1589
1592
  context 'when the Faraday adapter is set in the block' do
1593
+ require 'faraday/net_http_persistent' if is_faraday_v2?
1594
+
1590
1595
  let(:client) do
1591
1596
  described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1592
1597
  client.adapter(:net_http_persistent)
@@ -1747,6 +1752,7 @@ describe Elasticsearch::Transport::Client do
1747
1752
  end
1748
1753
 
1749
1754
  context 'when using the HTTPClient adapter' do
1755
+ require 'faraday/httpclient'
1750
1756
 
1751
1757
  let(:client) do
1752
1758
  described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)
@@ -53,7 +53,7 @@ if defined?(JRUBY_VERSION)
53
53
  expect(perform_request).to be_kind_of(Elasticsearch::Transport::Transport::Response)
54
54
  end
55
55
 
56
- it 'run body with preper params' do
56
+ it 'run body with proper params' do
57
57
  expect(
58
58
  client.transport.connections.first.connection
59
59
  ).to receive(:post).with('http://localhost:9200/', { body: body, headers: expected_headers }).and_return(response)
@@ -138,6 +138,24 @@ if defined?(JRUBY_VERSION)
138
138
  end
139
139
  end
140
140
  end
141
+
142
+ context 'headers' do
143
+ it 'sends custom headers' do
144
+ client = Elasticsearch::Transport::Client.new(
145
+ transport_class: described_class,
146
+ transport_options: { headers: { 'Elastic-Api-Version'=>'2023-10-31' } }
147
+ )
148
+ expect(
149
+ client.transport.connections.first.connection
150
+ ).to receive(:get).with(
151
+ 'http://localhost:9200/',
152
+ {
153
+ headers: expected_headers.merge({ 'Elastic-Api-Version'=>'2023-10-31' })
154
+ }
155
+ ).and_return(response)
156
+ client.perform_request('GET', '/', {}, nil, headers)
157
+ end
158
+ end
141
159
  end
142
160
  end
143
161
  end
@@ -172,7 +172,7 @@ describe Elasticsearch::Transport::Client do
172
172
  expect(headers).to include('x-elastic-client-meta' => meta)
173
173
 
174
174
  Typhoeus = @klass if was_required
175
- end unless jruby?
175
+ end
176
176
 
177
177
  it 'sets adapter in the meta header' do
178
178
  require 'typhoeus'
@@ -180,7 +180,7 @@ describe Elasticsearch::Transport::Client do
180
180
  meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
181
181
  expect(headers).to include('x-elastic-client-meta' => meta)
182
182
  end
183
- end
183
+ end unless jruby?
184
184
 
185
185
  unless jruby?
186
186
  let(:adapter) { :patron }
data/spec/spec_helper.rb CHANGED
@@ -75,6 +75,10 @@ def default_client
75
75
  $client ||= Elasticsearch::Client.new(hosts: ELASTICSEARCH_HOSTS)
76
76
  end
77
77
 
78
+ def is_faraday_v2?
79
+ Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
80
+ end
81
+
78
82
  module Config
79
83
  def self.included(context)
80
84
  # Get the hosts to use to connect an elasticsearch client.
@@ -17,7 +17,7 @@
17
17
 
18
18
  require 'test_helper'
19
19
 
20
- class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
20
+ class Elasticsearch::Transport::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
21
21
  startup do
22
22
  Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 2) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
23
23
  end
@@ -30,69 +30,115 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
30
30
  setup do
31
31
  @host, @port = ELASTICSEARCH_HOSTS.first.split(':')
32
32
  @hosts = { hosts: [ { host: @host, port: @port } ] }
33
- begin; Object.send(:remove_const, :Patron); rescue NameError; end
34
33
  end
35
34
 
36
- should "allow to customize the Faraday adapter to Typhoeus" do
37
- require 'typhoeus'
38
- require 'typhoeus/adapters/faraday'
39
-
35
+ should "use the default Faraday adapter" do
40
36
  transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
41
37
  f.response :logger
42
- f.adapter :typhoeus
43
38
  end
44
39
 
45
40
  client = Elasticsearch::Transport::Client.new transport: transport
41
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
46
42
  client.perform_request 'GET', ''
47
- end unless jruby?
43
+ end
44
+
45
+ unless jruby?
46
+ should "allow to customize the Faraday adapter to Typhoeus" do
47
+ if is_faraday_v2?
48
+ require 'faraday/typhoeus'
49
+ else
50
+ require 'typhoeus'
51
+ end
52
+
53
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
54
+ f.response :logger
55
+ f.adapter :typhoeus
56
+ end
57
+
58
+ client = Elasticsearch::Transport::Client.new transport: transport
59
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
60
+ client.perform_request 'GET', ''
61
+ end
48
62
 
49
- should "allow to customize the Faraday adapter to NetHttpPersistent" do
50
- require 'net/http/persistent'
63
+ should "use the Curb client" do
64
+ require 'curb'
65
+ require 'elasticsearch/transport/transport/http/curb'
66
+ transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
67
+ curl.verbose = true
68
+ end
51
69
 
52
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
53
- f.response :logger
54
- f.adapter :net_http_persistent
70
+ client = Elasticsearch::Transport::Client.new transport: transport
71
+ assert_equal(client.transport.class, Elasticsearch::Transport::Transport::HTTP::Curb)
72
+ client.perform_request 'GET', ''
55
73
  end
56
74
 
57
- client = Elasticsearch::Transport::Client.new transport: transport
58
- client.perform_request 'GET', ''
59
- end
75
+ should "deserialize JSON responses in the Curb client" do
76
+ require 'curb'
77
+ require 'elasticsearch/transport/transport/http/curb'
78
+ transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
79
+ curl.verbose = true
80
+ end
60
81
 
61
- should "allow to define connection parameters and pass them" do
62
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
63
- hosts: [ { host: @host, port: @port } ],
64
- options: { transport_options: { params: { :format => 'yaml' } } }
65
- )
66
- client = Elasticsearch::Transport::Client.new transport: transport
67
- response = client.perform_request 'GET', ''
82
+ client = Elasticsearch::Transport::Client.new transport: transport
83
+ response = client.perform_request 'GET', ''
68
84
 
69
- assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
70
- end
85
+ assert_respond_to(response.body, :to_hash)
86
+ assert_not_nil response.body['name']
87
+ assert_equal 'application/json', response.headers['content-type']
88
+ end
71
89
 
72
- should "use the Curb client" do
73
- require 'curb'
74
- require 'elasticsearch/transport/transport/http/curb'
75
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
76
- curl.verbose = true
90
+ should 'allow to customize the Faraday adapter to Patron' do
91
+ if is_faraday_v2?
92
+ require 'faraday/patron'
93
+ else
94
+ require 'patron'
95
+ end
96
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
97
+ f.response :logger
98
+ f.adapter :patron
99
+ end
100
+
101
+ client = Elasticsearch::Transport::Client.new(transport: transport)
102
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
103
+ client.perform_request 'GET', ''
77
104
  end
78
105
 
79
- client = Elasticsearch::Transport::Client.new transport: transport
80
- client.perform_request 'GET', ''
81
- end unless jruby?
106
+ should "allow to customize the Faraday adapter to NetHttpPersistent" do
107
+ require 'faraday/net_http_persistent'
82
108
 
83
- should "deserialize JSON responses in the Curb client" do
84
- require 'curb'
85
- require 'elasticsearch/transport/transport/http/curb'
86
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
87
- curl.verbose = true
109
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
110
+ f.response :logger
111
+ f.adapter :net_http_persistent
112
+ end
113
+
114
+ client = Elasticsearch::Transport::Client.new transport: transport
115
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
116
+ client.perform_request 'GET', ''
88
117
  end
89
118
 
90
- client = Elasticsearch::Transport::Client.new transport: transport
91
- response = client.perform_request 'GET', ''
119
+ should 'allow to customize the Faraday adapter to HTTPClient' do
120
+ require 'faraday/httpclient'
121
+
122
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
123
+ f.response :logger
124
+ f.adapter :httpclient
125
+ end
92
126
 
93
- assert_respond_to(response.body, :to_hash)
94
- assert_not_nil response.body['name']
95
- assert_equal 'application/json', response.headers['content-type']
96
- end unless jruby?
127
+ client = Elasticsearch::Transport::Client.new(transport: transport)
128
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
129
+ client.perform_request 'GET', ''
130
+ end
131
+
132
+ should "allow to define connection parameters and pass them" do
133
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
134
+ hosts: [ { host: @host, port: @port } ],
135
+ options: { transport_options: { params: { :format => 'yaml' } } }
136
+ )
137
+ client = Elasticsearch::Transport::Client.new transport: transport
138
+ response = client.perform_request 'GET', ''
139
+
140
+ assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
141
+ end
142
+ end
97
143
  end
98
144
  end
data/test/test_helper.rb CHANGED
@@ -97,6 +97,10 @@ module Minitest
97
97
  end
98
98
  end
99
99
 
100
+ def is_faraday_v2?
101
+ Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
102
+ end
103
+
100
104
  Minitest::Reporters.use! FixedMinitestSpecReporter.new
101
105
 
102
106
  module Elasticsearch
@@ -0,0 +1,88 @@
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 'test_helper'
19
+
20
+ class Elasticsearch::Transport::Transport::ClientAdaptersUnitTest < Minitest::Test
21
+ context 'Adapters' do
22
+ setup do
23
+ begin
24
+ Object.send(:remove_const, :Patron)
25
+ rescue NameError
26
+ end
27
+ end
28
+
29
+ should 'use the default Faraday adapter' do
30
+ fork do
31
+ client = Elasticsearch::Transport::Client.new
32
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
33
+ end
34
+ end
35
+
36
+ should 'use Patron Faraday adapter' do
37
+ fork do
38
+ if is_faraday_v2?
39
+ require 'faraday/patron'
40
+ else
41
+ require 'patron'
42
+ end
43
+
44
+ client = Elasticsearch::Transport::Client.new
45
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
46
+ end
47
+ end
48
+
49
+ should 'use Typhoeus Faraday adapter' do
50
+ fork do
51
+ if is_faraday_v2?
52
+ require 'faraday/typhoeus'
53
+ else
54
+ require 'typhoeus'
55
+ end
56
+
57
+ client = Elasticsearch::Transport::Client.new
58
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
59
+ end
60
+ end
61
+
62
+ should 'use NetHttpPersistent Faraday adapter' do
63
+ fork do
64
+ if is_faraday_v2?
65
+ require 'faraday/net_http_persistent'
66
+ else
67
+ require 'net/http/persistent'
68
+ end
69
+
70
+ client = Elasticsearch::Transport::Client.new
71
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
72
+ end
73
+ end
74
+
75
+ should 'use HTTPClient Faraday adapter' do
76
+ fork do
77
+ if is_faraday_v2?
78
+ require 'faraday/httpclient'
79
+ else
80
+ require 'httpclient'
81
+ end
82
+
83
+ client = Elasticsearch::Transport::Client.new
84
+ assert_equal(Faraday::Adapter::HTTPClient, client.transport.connections.first.connection.adapter)
85
+ end
86
+ end
87
+ end unless jruby?
88
+ end
@@ -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: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.17.8
4
+ version: 7.17.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-05 00:00:00.000000000 Z
11
+ date: 2023-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -28,18 +28,24 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
41
47
  - !ruby/object:Gem::Dependency
42
- name: ansi
48
+ name: curb
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - ">="
@@ -53,7 +59,7 @@ dependencies:
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
- name: bundler
62
+ name: ansi
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - ">="
@@ -67,7 +73,7 @@ dependencies:
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: cane
76
+ name: bundler
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - ">="
@@ -81,7 +87,7 @@ dependencies:
81
87
  - !ruby/object:Gem::Version
82
88
  version: '0'
83
89
  - !ruby/object:Gem::Dependency
84
- name: curb
90
+ name: cane
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - ">="
@@ -142,20 +148,6 @@ dependencies:
142
148
  - - ">="
143
149
  - !ruby/object:Gem::Version
144
150
  version: '0'
145
- - !ruby/object:Gem::Dependency
146
- name: httpclient
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - ">="
150
- - !ruby/object:Gem::Version
151
- version: '0'
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- version: '0'
159
151
  - !ruby/object:Gem::Dependency
160
152
  name: minitest
161
153
  requirement: !ruby/object:Gem::Requirement
@@ -198,20 +190,6 @@ dependencies:
198
190
  - - ">="
199
191
  - !ruby/object:Gem::Version
200
192
  version: '0'
201
- - !ruby/object:Gem::Dependency
202
- name: net-http-persistent
203
- requirement: !ruby/object:Gem::Requirement
204
- requirements:
205
- - - ">="
206
- - !ruby/object:Gem::Version
207
- version: '0'
208
- type: :development
209
- prerelease: false
210
- version_requirements: !ruby/object:Gem::Requirement
211
- requirements:
212
- - - ">="
213
- - !ruby/object:Gem::Version
214
- version: '0'
215
193
  - !ruby/object:Gem::Dependency
216
194
  name: patron
217
195
  requirement: !ruby/object:Gem::Requirement
@@ -324,20 +302,6 @@ dependencies:
324
302
  - - "~>"
325
303
  - !ruby/object:Gem::Version
326
304
  version: '2'
327
- - !ruby/object:Gem::Dependency
328
- name: typhoeus
329
- requirement: !ruby/object:Gem::Requirement
330
- requirements:
331
- - - "~>"
332
- - !ruby/object:Gem::Version
333
- version: '1.4'
334
- type: :development
335
- prerelease: false
336
- version_requirements: !ruby/object:Gem::Requirement
337
- requirements:
338
- - - "~>"
339
- - !ruby/object:Gem::Version
340
- version: '1.4'
341
305
  - !ruby/object:Gem::Dependency
342
306
  name: yard
343
307
  requirement: !ruby/object:Gem::Requirement
@@ -366,6 +330,7 @@ extra_rdoc_files:
366
330
  files:
367
331
  - ".gitignore"
368
332
  - Gemfile
333
+ - Gemfile-faraday1.gemfile
369
334
  - LICENSE
370
335
  - README.md
371
336
  - Rakefile
@@ -402,6 +367,7 @@ files:
402
367
  - test/integration/transport_test.rb
403
368
  - test/profile/client_benchmark_test.rb
404
369
  - test/test_helper.rb
370
+ - test/unit/adapters_test.rb
405
371
  - test/unit/connection_test.rb
406
372
  - test/unit/response_test.rb
407
373
  - test/unit/serializer_test.rb
@@ -452,6 +418,7 @@ test_files:
452
418
  - test/integration/transport_test.rb
453
419
  - test/profile/client_benchmark_test.rb
454
420
  - test/test_helper.rb
421
+ - test/unit/adapters_test.rb
455
422
  - test/unit/connection_test.rb
456
423
  - test/unit/response_test.rb
457
424
  - test/unit/serializer_test.rb