Skip to content

Commit b37fe44

Browse files
committed
[CLIENT] Updates manticore headers setup
1 parent be5d514 commit b37fe44

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
module Elasticsearch
1919
module Transport
2020
module Transport
21-
2221
# @abstract Module with common functionality for transport implementations.
2322
#
2423
module Base
@@ -431,7 +430,7 @@ def apply_headers(client, options)
431430
end
432431

433432
def find_value(hash, regex)
434-
key_value = hash.find { |k,v| k.to_s.downcase =~ regex }
433+
key_value = hash.find { |k, _| k.to_s.downcase =~ regex }
435434
if key_value
436435
hash.delete(key_value[0])
437436
key_value[1]

elasticsearch-transport/lib/elasticsearch/transport/transport/http/manticore.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ module HTTP
6262
class Manticore
6363
include Base
6464

65-
def initialize(arguments={}, &block)
66-
@request_options = { headers: (arguments.dig(:transport_options, :headers) || {}) }
65+
def initialize(arguments = {}, &block)
66+
@request_options = {
67+
headers: (
68+
arguments.dig(:transport_options, :headers) ||
69+
arguments.dig(:options, :transport_options, :headers) ||
70+
{}
71+
)
72+
}
6773
@manticore = build_client(arguments[:options] || {})
6874
super(arguments, &block)
6975
end
@@ -113,8 +119,7 @@ def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
113119
# @return [Connections::Collection]
114120
#
115121
def __build_connections
116-
apply_headers(@request_options, options[:transport_options])
117-
apply_headers(@request_options, options)
122+
apply_headers(options)
118123

119124
Connections::Collection.new \
120125
:connections => hosts.map { |host|
@@ -157,12 +162,12 @@ def host_unreachable_exceptions
157162

158163
private
159164

160-
def apply_headers(request_options, options)
161-
headers = options&.[](:headers) || {}
165+
def apply_headers(options)
166+
headers = options.dig(:headers) || options.dig(:transport_options, :headers) || {}
162167
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
163-
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header
168+
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || find_value(@request_options[:headers], USER_AGENT_REGEX) || user_agent_header
164169
headers[ACCEPT_ENCODING] = GZIP if use_compression?
165-
request_options[:headers].merge!(headers)
170+
@request_options[:headers].merge!(headers)
166171
end
167172

168173
def user_agent_header

0 commit comments

Comments
 (0)