elasticsearch-transport 6.0.1 → 6.0.2
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 +2 -2
- data/lib/elasticsearch/transport/transport/base.rb +9 -5
- data/lib/elasticsearch/transport/transport/http/curb.rb +2 -1
- data/lib/elasticsearch/transport/transport/http/faraday.rb +2 -2
- data/lib/elasticsearch/transport/transport/http/manticore.rb +2 -1
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/test/integration/client_test.rb +5 -0
- data/test/unit/client_test.rb +8 -1
- data/test/unit/transport_base_test.rb +1 -1
- data/test/unit/transport_curb_test.rb +8 -0
- data/test/unit/transport_faraday_test.rb +12 -0
- data/test/unit/transport_manticore_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0958ecd0da7c46d4bf09410e6d420e7d9379e89c'
|
4
|
+
data.tar.gz: f9e1a3bc7db0bb0b084475141b1efa002edc3261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d69cb26a0ba4f1e93bfb82b325f6eedc840458b4df1371d6036341c582231c637779713f1150b7002545c075def4796b5229344d64ae34f1bd88ec8baafff6
|
7
|
+
data.tar.gz: c3101a660dd94e88d8f5289b15ab4aab27497c83219e30860d75545ba780d8c2fbc6d2b0da844d4e41b095d81b36e754cd14e4a8b2734d48af4cde371eb55423
|
@@ -125,10 +125,10 @@ module Elasticsearch
|
|
125
125
|
|
126
126
|
# Performs a request through delegation to {#transport}.
|
127
127
|
#
|
128
|
-
def perform_request(method, path, params={}, body=nil)
|
128
|
+
def perform_request(method, path, params={}, body=nil, headers=nil)
|
129
129
|
method = @send_get_body_as if 'GET' == method && body
|
130
130
|
|
131
|
-
transport.perform_request method, path, params, body
|
131
|
+
transport.perform_request method, path, params, body, headers
|
132
132
|
end
|
133
133
|
|
134
134
|
# Normalizes and returns hosts configuration.
|
@@ -184,11 +184,14 @@ module Elasticsearch
|
|
184
184
|
#
|
185
185
|
# @api private
|
186
186
|
#
|
187
|
-
def __trace(method, path, params, body, url, response, json, took, duration)
|
187
|
+
def __trace(method, path, params, headers, body, url, response, json, took, duration)
|
188
188
|
trace_url = "http://localhost:9200/#{path}?pretty" +
|
189
189
|
( params.empty? ? '' : "&#{::Faraday::Utils::ParamsHash[params].to_query}" )
|
190
190
|
trace_body = body ? " -d '#{__convert_to_json(body, :pretty => true)}'" : ''
|
191
|
-
|
191
|
+
trace_command = "curl -X #{method.to_s.upcase}"
|
192
|
+
trace_command += " -H '#{headers.inject('') { |memo,item| memo << item[0] + ': ' + item[1] }}'" if headers && !headers.empty?
|
193
|
+
trace_command += " '#{trace_url}'#{trace_body}\n"
|
194
|
+
tracer.info trace_command
|
192
195
|
tracer.debug "# #{Time.now.iso8601} [#{response.status}] (#{format('%.3f', duration)}s)\n#"
|
193
196
|
tracer.debug json ? serializer.dump(json, :pretty => true).gsub(/^/, '# ').sub(/\}$/, "\n# }")+"\n" : "# #{response.body}\n"
|
194
197
|
end
|
@@ -233,6 +236,7 @@ module Elasticsearch
|
|
233
236
|
# @param path [String] The API endpoint
|
234
237
|
# @param params [Hash] Request parameters (will be serialized by {Connections::Connection#full_url})
|
235
238
|
# @param body [Hash] Request body (will be serialized by the {#serializer})
|
239
|
+
# @param headers [Hash] Request headers (will be serialized by the {#serializer})
|
236
240
|
# @param block [Proc] Code block to evaluate, passed from the implementation
|
237
241
|
#
|
238
242
|
# @return [Response]
|
@@ -240,7 +244,7 @@ module Elasticsearch
|
|
240
244
|
# @raise [ServerError] If request failed on server
|
241
245
|
# @raise [Error] If no connection is available
|
242
246
|
#
|
243
|
-
def perform_request(method, path, params={}, body=nil, &block)
|
247
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, &block)
|
244
248
|
raise NoMethodError, "Implement this method in your transport class" unless block_given?
|
245
249
|
start = Time.now if logger || tracer
|
246
250
|
tries = 0
|
@@ -311,7 +315,7 @@ module Elasticsearch
|
|
311
315
|
|
312
316
|
if response.status.to_i >= 300
|
313
317
|
__log method, path, params, body, url, response, nil, 'N/A', duration if logger
|
314
|
-
__trace method, path, params, body, url, response, nil, 'N/A', duration if tracer
|
318
|
+
__trace method, path, params, headers, body, url, response, nil, 'N/A', duration if tracer
|
315
319
|
|
316
320
|
# Log the failure only when `ignore` doesn't match the response status
|
317
321
|
__log_failed response if logger && !ignore.include?(response.status.to_i)
|
@@ -323,7 +327,7 @@ module Elasticsearch
|
|
323
327
|
took = (json['took'] ? sprintf('%.3fs', json['took']/1000.0) : 'n/a') rescue 'n/a' if logger || tracer
|
324
328
|
|
325
329
|
__log method, path, params, body, url, response, json, took, duration if logger && !ignore.include?(response.status.to_i)
|
326
|
-
__trace method, path, params, body, url, response, json, took, duration if tracer
|
330
|
+
__trace method, path, params, headers, body, url, response, json, took, duration if tracer
|
327
331
|
|
328
332
|
Response.new response.status, json || response.body, response.headers
|
329
333
|
ensure
|
@@ -15,7 +15,7 @@ module Elasticsearch
|
|
15
15
|
# @return [Response]
|
16
16
|
# @see Transport::Base#perform_request
|
17
17
|
#
|
18
|
-
def perform_request(method, path, params={}, body=nil)
|
18
|
+
def perform_request(method, path, params={}, body=nil, headers=nil)
|
19
19
|
super do |connection,url|
|
20
20
|
connection.connection.url = url
|
21
21
|
|
@@ -26,6 +26,7 @@ module Elasticsearch
|
|
26
26
|
connection.connection.set :nobody, false
|
27
27
|
|
28
28
|
connection.connection.put_data = __convert_to_json(body) if body
|
29
|
+
connection.connection.headers = headers if headers
|
29
30
|
else raise ArgumentError, "Unsupported HTTP method: #{method}"
|
30
31
|
end
|
31
32
|
|
@@ -16,9 +16,9 @@ module Elasticsearch
|
|
16
16
|
# @return [Response]
|
17
17
|
# @see Transport::Base#perform_request
|
18
18
|
#
|
19
|
-
def perform_request(method, path, params={}, body=nil)
|
19
|
+
def perform_request(method, path, params={}, body=nil, headers=nil)
|
20
20
|
super do |connection, url|
|
21
|
-
headers = connection.connection.headers
|
21
|
+
headers = headers || connection.connection.headers
|
22
22
|
|
23
23
|
response = connection.connection.run_request \
|
24
24
|
method.downcase.to_sym,
|
@@ -63,9 +63,10 @@ module Elasticsearch
|
|
63
63
|
# @return [Response]
|
64
64
|
# @see Transport::Base#perform_request
|
65
65
|
#
|
66
|
-
def perform_request(method, path, params={}, body=nil)
|
66
|
+
def perform_request(method, path, params={}, body=nil, headers=nil)
|
67
67
|
super do |connection, url|
|
68
68
|
params[:body] = __convert_to_json(body) if body
|
69
|
+
params[:headers] = headers if headers
|
69
70
|
params = params.merge @request_options
|
70
71
|
case method
|
71
72
|
when "GET"
|
@@ -73,6 +73,11 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
73
73
|
assert_equal 'application/yaml', response.headers['content-type']
|
74
74
|
end
|
75
75
|
|
76
|
+
should "pass request headers to the transport" do
|
77
|
+
response = @client.perform_request 'GET', '/', {}, nil, {'Content-Type' => 'application/yaml'}
|
78
|
+
assert_match(/---/, response.body)
|
79
|
+
end
|
80
|
+
|
76
81
|
should "pass options to the Faraday::Connection with a block" do
|
77
82
|
@client = Elasticsearch::Client.new(
|
78
83
|
host: "127.0.0.1:#{@port}",
|
data/test/unit/client_test.rb
CHANGED
@@ -41,10 +41,17 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
|
|
41
41
|
should "send GET request as POST with the send_get_body_as option" do
|
42
42
|
transport = DummyTransport.new
|
43
43
|
client = Elasticsearch::Transport::Client.new :transport => transport, :send_get_body_as => 'POST'
|
44
|
-
transport.expects(:perform_request).with 'POST', '/', {}, '{"foo":"bar"}'
|
44
|
+
transport.expects(:perform_request).with 'POST', '/', {}, '{"foo":"bar"}', nil
|
45
45
|
client.perform_request 'GET', '/', {}, '{"foo":"bar"}'
|
46
46
|
end
|
47
47
|
|
48
|
+
should "call perform_request with custom headers" do
|
49
|
+
transport = DummyTransport.new
|
50
|
+
client = Elasticsearch::Transport::Client.new :transport => transport, :send_get_body_as => 'POST'
|
51
|
+
transport.expects(:perform_request).with 'POST', '/', {}, '{"foo":"bar"}', '{"Content-Type":"application/x-ndjson"}'
|
52
|
+
client.perform_request 'POST', '/', {}, '{"foo":"bar"}', '{"Content-Type":"application/x-ndjson"}'
|
53
|
+
end
|
54
|
+
|
48
55
|
should "have default logger for transport" do
|
49
56
|
client = Elasticsearch::Transport::Client.new :log => true
|
50
57
|
assert_respond_to client.transport.logger, :info
|
@@ -353,7 +353,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
|
|
353
353
|
never
|
354
354
|
|
355
355
|
assert_raise Elasticsearch::Transport::Transport::Errors::BadRequest do
|
356
|
-
@transport.perform_request('GET', '/', &@block)
|
356
|
+
@transport.perform_request('GET', '/', {}, nil, &@block)
|
357
357
|
end
|
358
358
|
end
|
359
359
|
|
@@ -37,6 +37,14 @@ else
|
|
37
37
|
@transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
|
38
38
|
end
|
39
39
|
|
40
|
+
should "perform request with headers" do
|
41
|
+
@transport.connections.first.connection.expects(:put_data=).with('{"foo":"bar"}')
|
42
|
+
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
|
43
|
+
@transport.connections.first.connection.expects(:headers=).with({"Content-Type" => "application/x-ndjson"})
|
44
|
+
|
45
|
+
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
|
46
|
+
end
|
47
|
+
|
40
48
|
should "set body for PUT request" do
|
41
49
|
@transport.connections.first.connection.expects(:put_data=)
|
42
50
|
@transport.connections.first.connection.expects(:http).with(:PUT).returns(stub_everything)
|
@@ -42,6 +42,18 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
42
42
|
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}
|
43
43
|
end
|
44
44
|
|
45
|
+
should "properly prepare the request with custom headers" do
|
46
|
+
@transport.connections.first.connection.expects(:run_request).with do |method, url, body, headers|
|
47
|
+
assert_equal :post, method
|
48
|
+
assert_equal '{"foo":"bar"}', body
|
49
|
+
assert_nil headers['Accept']
|
50
|
+
assert_equal "application/x-ndjson", headers['Content-Type']
|
51
|
+
true
|
52
|
+
end.returns(stub_everything)
|
53
|
+
|
54
|
+
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
|
55
|
+
end
|
56
|
+
|
45
57
|
should "properly pass the Content-Type header option" do
|
46
58
|
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => { :transport_options => { :headers => { 'Content-Type' => 'foo/bar' } } }
|
47
59
|
|
@@ -55,6 +55,13 @@ else
|
|
55
55
|
@transport.perform_request 'POST', '/', {}, {'foo' => 'bar'}
|
56
56
|
end
|
57
57
|
|
58
|
+
should "set custom headers for PUT request" do
|
59
|
+
@transport.connections.first.connection.expects(:put).
|
60
|
+
with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}', :headers => {"Content-Type" => "application/x-ndjson"}})
|
61
|
+
.returns(stub_everything)
|
62
|
+
@transport.perform_request 'PUT', '/', {}, '{"foo":"bar"}', {"Content-Type" => "application/x-ndjson"}
|
63
|
+
end
|
64
|
+
|
58
65
|
should "not serialize a String request body" do
|
59
66
|
@transport.connections.first.connection.expects(:post).
|
60
67
|
with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).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: 6.0.
|
4
|
+
version: 6.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|