File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
lib/elasticsearch/transport
spec/elasticsearch/transport Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -209,8 +209,10 @@ def add_header(header)
209
209
def set_meta_header
210
210
return if @arguments [ :enable_meta_header ] == false
211
211
212
+ service , version = meta_header_service_version
213
+
212
214
meta_headers = {
213
- es : Elasticsearch :: VERSION , # TODO - es|ent
215
+ service . to_sym => version ,
214
216
rb : RUBY_VERSION ,
215
217
t : Elasticsearch ::Transport ::VERSION
216
218
}
@@ -220,6 +222,16 @@ def set_meta_header
220
222
add_header ( { 'x-elastic-client-meta' => meta_headers . map { |k , v | "#{ k } =#{ v } " } . join ( ',' ) } )
221
223
end
222
224
225
+ def meta_header_service_version
226
+ if defined? ( Elastic ::META_HEADER_SERVICE_VERSION )
227
+ Elastic ::META_HEADER_SERVICE_VERSION
228
+ elsif defined? ( Elasticsearch ::VERSION )
229
+ [ 'es' , Elasticsearch ::VERSION ]
230
+ else
231
+ [ 'es' , Elasticsearch ::Transport ::VERSION ]
232
+ end
233
+ end
234
+
223
235
def meta_header_engine
224
236
case RUBY_ENGINE
225
237
when 'ruby'
Original file line number Diff line number Diff line change @@ -178,5 +178,26 @@ def initialize(args); end
178
178
expect ( subject ) . to include ( 'x-elastic-client-meta' => meta_header )
179
179
end
180
180
end
181
+
182
+ context 'when using a different service version' do
183
+ before do
184
+ module Elastic
185
+ META_HEADER_SERVICE_VERSION = [ :ent , '8.0.0' ]
186
+ end
187
+ end
188
+
189
+ after do
190
+ module Elastic
191
+ META_HEADER_SERVICE_VERSION = [ :es , Elasticsearch ::VERSION ]
192
+ end
193
+ end
194
+
195
+ let ( :client ) { Elasticsearch ::Client . new }
196
+
197
+ it 'sets the service version in the metaheader' do
198
+ expect ( subject [ 'x-elastic-client-meta' ] ) . to match ( regexp )
199
+ expect ( subject [ 'x-elastic-client-meta' ] ) . to start_with ( 'ent=8.0.0' )
200
+ end
201
+ end
181
202
end
182
203
end
Original file line number Diff line number Diff line change @@ -27,3 +27,7 @@ class Client
27
27
end
28
28
end
29
29
end
30
+ module Elastic
31
+ # Constant for elasticsearch-transport meta-header
32
+ META_HEADER_SERVICE_VERSION = [ :es , Elasticsearch ::VERSION ]
33
+ end
Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ class ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
70
70
end
71
71
end
72
72
73
+ should 'report the right meta header' do
74
+ headers = @client . transport . connections . first . connection . headers
75
+ assert_match /^es=#{ Elasticsearch ::VERSION } / , headers [ 'x-elastic-client-meta' ]
76
+ end
73
77
end
74
78
end
75
79
end
You can’t perform that action at this time.
0 commit comments