[Backport 7.x] Added x-elastic-client-meta header (#1377)
Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
48762f12ec
commit
39ce8778a5
17
index.js
17
index.js
@ -33,6 +33,8 @@ const Serializer = require('./lib/Serializer')
|
||||
const errors = require('./lib/errors')
|
||||
const { ConfigurationError } = errors
|
||||
const { prepareHeaders } = Connection.internals
|
||||
const clientVersion = require('./package.json').version
|
||||
const nodeVersion = process.versions.node
|
||||
|
||||
const kInitialOptions = Symbol('elasticsearchjs-initial-options')
|
||||
const kChild = Symbol('elasticsearchjs-child')
|
||||
@ -125,13 +127,18 @@ class Client extends ESAPI {
|
||||
auth: null,
|
||||
opaqueIdPrefix: null,
|
||||
context: null,
|
||||
proxy: null
|
||||
proxy: null,
|
||||
enableMetaHeader: true
|
||||
}, opts)
|
||||
|
||||
this[kInitialOptions] = options
|
||||
this[kExtensions] = []
|
||||
this.name = options.name
|
||||
|
||||
if (options.enableMetaHeader) {
|
||||
options.headers['x-elastic-client-meta'] = `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}`
|
||||
}
|
||||
|
||||
if (opts[kChild] !== undefined) {
|
||||
this.serializer = options[kChild].serializer
|
||||
this.connectionPool = options[kChild].connectionPool
|
||||
@ -179,7 +186,13 @@ class Client extends ESAPI {
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (Helpers !== null) {
|
||||
this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
|
||||
this.helpers = new Helpers({
|
||||
client: this,
|
||||
maxRetries: options.maxRetries,
|
||||
metaHeader: options.enableMetaHeader
|
||||
? `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}`
|
||||
: null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user