lib/elasticsearch/transport/meta_header.rb in elasticsearch-transport-7.12.0 vs lib/elasticsearch/transport/meta_header.rb in elasticsearch-transport-7.13.0.pre
- old
+ new
@@ -17,11 +17,10 @@
require 'base64'
module Elasticsearch
module Transport
-
# Methods for the Elastic meta header used by Cloud.
# X-Elastic-Client-Meta HTTP header which is used by Elastic Cloud and can be disabled when
# instantiating the Client with the :enable_meta_header parameter set to `false`.
#
module MetaHeader
@@ -40,16 +39,32 @@
add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
end
def meta_header_service_version
- if defined?(Elastic::META_HEADER_SERVICE_VERSION)
- Elastic::META_HEADER_SERVICE_VERSION
+ if enterprise_search?
+ Elastic::ENTERPRISE_SERVICE_VERSION
+ elsif elasticsearch?
+ Elastic::ELASTICSEARCH_SERVICE_VERSION
elsif defined?(Elasticsearch::VERSION)
[:es, client_meta_version(Elasticsearch::VERSION)]
else
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
end
+ end
+
+ def enterprise_search?
+ defined?(Elastic::ENTERPRISE_SERVICE_VERSION) &&
+ called_from?('enterprise-search-ruby')
+ end
+
+ def elasticsearch?
+ defined?(Elastic::ELASTICSEARCH_SERVICE_VERSION) &&
+ called_from?('elasticsearch')
+ end
+
+ def called_from?(service)
+ !caller.select { |c| c.match?(service) }.empty?
end
# We return the current version if it's a release, but if it's a pre/alpha/beta release we
# return <VERSION_NUMBER>p
#