This commit is contained in:
Fabio Niephaus 2022-10-27 19:06:03 -05:00 committed by GitHub
commit 92248290af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -62,6 +62,21 @@ describe('basics', () => {
done()
})
it('does basic http get request with overridden user agent', async done => {
let res: httpm.HttpClientResponse = await _http.get(
'http://httpbin.org/get',
{
'user-agent': 'custom-user-agent'
}
)
expect(res.message.statusCode).toBe(200)
let body: string = await res.readBody()
let obj: any = JSON.parse(body)
expect(obj.url).toBe('http://httpbin.org/get')
expect(obj.headers['User-Agent']).toBe('custom-user-agent')
done()
})
it('does basic https get request', async done => {
let res: httpm.HttpClientResponse = await _http.get(
'https://httpbin.org/get'

View File

@ -562,7 +562,7 @@ export class HttpClient {
(info.parsedUrl.pathname || '') + (info.parsedUrl.search || '')
info.options.method = method
info.options.headers = this._mergeHeaders(headers)
if (this.userAgent != null) {
if (this.userAgent != null && !('user-agent' in info.options.headers)) {
info.options.headers['user-agent'] = this.userAgent
}