Use correct user-agent header by default (#1865)

This commit is contained in:
Josh Mock
2023-05-05 10:48:41 -05:00
committed by GitHub
parent b2b54f1ffe
commit bdb44d6d9a
2 changed files with 13 additions and 1 deletions

View File

@ -20,6 +20,7 @@
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
import { URL } from 'url'
import buffer from 'buffer'
import os from 'os'
import {
Transport,
UndiciConnection,
@ -173,7 +174,9 @@ export default class Client extends API {
tls: null,
caFingerprint: null,
agent: null,
headers: {},
headers: {
'user-agent': `elasticsearch-js/${clientVersion} Node.js ${nodeVersion}; Transport ${transportVersion}; (${os.platform()} ${os.release()} ${os.arch()})`
},
nodeFilter: null,
generateRequestId: null,
name: 'elasticsearch-js',

View File

@ -432,3 +432,12 @@ test('caFingerprint can\'t be configured over http / 2', t => {
)
t.end()
})
test('user agent is in the correct format', t => {
const client = new Client({ node: 'http://localhost:9200' })
const agentRaw = client.transport[symbols.kHeaders]['user-agent'] || ''
const agentSplit = agentRaw.split(/\s+/)
t.equal(agentSplit[0].split('/')[0], 'elasticsearch-js')
t.ok(/^\d+\.\d+\.\d+/.test(agentSplit[0].split('/')[1]))
t.end()
})