Module: Elastic::Transport::MetaHeader
- Included in:
- Client
- Defined in:
- lib/elastic/transport/meta_header.rb
Overview
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`.
Instance Method Summary collapse
- #called_from?(service) ⇒ Boolean
-
#client_meta_version(version) ⇒ Object
We return the current version if it’s a release, but if it’s a pre/alpha/beta release we return <VERSION_NUMBER>p.
- #elasticsearch? ⇒ Boolean
- #enterprise_search? ⇒ Boolean
-
#meta_header_adapter ⇒ Object
This function tries to define the version for the Faraday adapter.
- #meta_header_engine ⇒ Object
- #meta_header_service_version ⇒ Object
- #set_meta_header ⇒ Object
Instance Method Details
#called_from?(service) ⇒ Boolean
63 64 65 |
# File 'lib/elastic/transport/meta_header.rb', line 63 def called_from?(service) !caller.select { |c| c.match?(service) }.empty? end |
#client_meta_version(version) ⇒ Object
We return the current version if it’s a release, but if it’s a pre/alpha/beta release we return <VERSION_NUMBER>p
70 71 72 73 74 75 76 |
# File 'lib/elastic/transport/meta_header.rb', line 70 def (version) regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/ match = version.match(regexp) return "#{match[1]}p" if (match[2]) version end |
#elasticsearch? ⇒ Boolean
58 59 60 61 |
# File 'lib/elastic/transport/meta_header.rb', line 58 def elasticsearch? defined?(Elastic::ELASTICSEARCH_SERVICE_VERSION) && called_from?('elasticsearch') end |
#enterprise_search? ⇒ Boolean
53 54 55 56 |
# File 'lib/elastic/transport/meta_header.rb', line 53 def enterprise_search? defined?(Elastic::ENTERPRISE_SERVICE_VERSION) && called_from?('enterprise-search-ruby') end |
#meta_header_adapter ⇒ Object
This function tries to define the version for the Faraday adapter. If it hasn’t been loaded by the time we’re calling this method, it’s going to report the adapter (if we know it) but return 0 as the version. It won’t report anything when using a custom adapter we don’t identify.
Returns a Hash<adapter_alias, version>
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/elastic/transport/meta_header.rb', line 98 def if @transport_class == Transport::HTTP::Faraday version = '0' adapter_version = case @arguments[:adapter] when :patron version = Patron::VERSION if defined?(::Patron::VERSION) { pt: version } when :net_http version = if defined?(Net::HTTP::VERSION) Net::HTTP::VERSION elsif defined?(Net::HTTP::HTTPVersion) Net::HTTP::HTTPVersion end { nh: version } when :typhoeus version = Typhoeus::VERSION if defined?(::Typhoeus::VERSION) { ty: version } when :httpclient version = HTTPClient::VERSION if defined?(HTTPClient::VERSION) { hc: version } when :net_http_persistent version = Net::HTTP::Persistent::VERSION if defined?(Net::HTTP::Persistent::VERSION) { np: version } else {} end { fd: Faraday::VERSION }.merge(adapter_version) elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb { cl: Curl::CURB_VERSION } elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore { mc: Manticore::VERSION } end end |
#meta_header_engine ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/elastic/transport/meta_header.rb', line 78 def case RUBY_ENGINE when 'ruby' {} when 'jruby' { jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION } when 'rbx' { rbx: RUBY_VERSION } else { RUBY_ENGINE.to_sym => RUBY_VERSION } end end |
#meta_header_service_version ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/elastic/transport/meta_header.rb', line 41 def if enterprise_search? Elastic::ENTERPRISE_SERVICE_VERSION elsif elasticsearch? Elastic::ELASTICSEARCH_SERVICE_VERSION elsif defined?(Elasticsearch::VERSION) [:es, (Elasticsearch::VERSION)] else [:et, (Elastic::Transport::VERSION)] end end |
#set_meta_header ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/elastic/transport/meta_header.rb', line 25 def return if @arguments[:enable_meta_header] == false service, version = = { service.to_sym => version, rb: RUBY_VERSION, t: Elastic::Transport::VERSION } .merge!() if .merge!() if add_header({ 'x-elastic-client-meta' => .map { |k, v| "#{k}=#{v}" }.join(',') }) end |