[Backport 8.7] Use correct user-agent header by default (#1866)
Co-authored-by: Josh Mock <josh@joshmock.com>
This commit is contained in:
committed by
GitHub
parent
fca53568d2
commit
ab8ff69eac
@ -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',
|
||||
|
||||
@ -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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user