add user-agent to http and ws requestor (#602)

* add user-agent to http and ws requestor

* wip

* fix review comment
This commit is contained in:
Hoan Luu Huu
2024-01-10 20:54:46 +07:00
committed by GitHub
parent 6f6d7a06b0
commit 29bbcf1be0
4 changed files with 14 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ const {
HTTP_PROXY_PORT,
HTTP_PROXY_PROTOCOL,
NODE_ENV,
HTTP_USER_AGENT_HEADER,
} = require('../config');
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
@@ -116,6 +117,10 @@ class HttpRequestor extends BaseRequestor {
const url = hook.url || hook;
const method = hook.method || 'POST';
let buf = '';
httpHeaders = {
...httpHeaders,
...(HTTP_USER_AGENT_HEADER && {'user-agent' : HTTP_USER_AGENT_HEADER})
};
assert.ok(url, 'HttpRequestor:request url was not provided');
assert.ok, (['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`);