[Backport 8.8] Use correct user-agent header by default (#1867)
Co-authored-by: Josh Mock <josh@joshmock.com>
This commit is contained in:
committed by
GitHub
parent
4a4624b3ad
commit
a33c7af5e8
@ -20,6 +20,7 @@
|
|||||||
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
|
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
import buffer from 'buffer'
|
import buffer from 'buffer'
|
||||||
|
import os from 'os'
|
||||||
import {
|
import {
|
||||||
Transport,
|
Transport,
|
||||||
UndiciConnection,
|
UndiciConnection,
|
||||||
@ -173,7 +174,9 @@ export default class Client extends API {
|
|||||||
tls: null,
|
tls: null,
|
||||||
caFingerprint: null,
|
caFingerprint: null,
|
||||||
agent: null,
|
agent: null,
|
||||||
headers: {},
|
headers: {
|
||||||
|
'user-agent': `elasticsearch-js/${clientVersion} Node.js ${nodeVersion}; Transport ${transportVersion}; (${os.platform()} ${os.release()} ${os.arch()})`
|
||||||
|
},
|
||||||
nodeFilter: null,
|
nodeFilter: null,
|
||||||
generateRequestId: null,
|
generateRequestId: null,
|
||||||
name: 'elasticsearch-js',
|
name: 'elasticsearch-js',
|
||||||
|
|||||||
@ -432,3 +432,12 @@ test('caFingerprint can\'t be configured over http / 2', t => {
|
|||||||
)
|
)
|
||||||
t.end()
|
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