Added User-Agent header (#807)

* Added User-Agent header

* Updated test

* Updated user-agent format

* Updated test
This commit is contained in:
Tomas Della Vedova
2019-05-06 09:59:22 +02:00
committed by delvedor
parent 0c1fb22631
commit 907f9d085c
2 changed files with 43 additions and 1 deletions

View File

@ -20,6 +20,7 @@
'use strict'
const debug = require('debug')('elasticsearch')
const os = require('os')
const once = require('once')
const { createGzip } = require('zlib')
const intoStream = require('into-stream')
@ -34,6 +35,9 @@ const {
const noop = () => {}
const clientVersion = require('../package.json').version
const userAgent = `elasticsearch-js/${clientVersion} (${os.platform()} ${os.release()}-${os.arch()}; Node.js ${process.version})`
class Transport {
constructor (opts = {}) {
if (typeof opts.compression === 'string' && opts.compression !== 'gzip') {
@ -46,7 +50,7 @@ class Transport {
this.requestTimeout = toMs(opts.requestTimeout)
this.suggestCompression = opts.suggestCompression === true
this.compression = opts.compression || false
this.headers = opts.headers || {}
this.headers = Object.assign({}, { 'User-Agent': userAgent }, opts.headers)
this.sniffInterval = opts.sniffInterval
this.sniffOnConnectionFault = opts.sniffOnConnectionFault
this.sniffEndpoint = opts.sniffEndpoint