-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Description
The inner browser check and isBrowser util can be factored out
lib/common/lib/headers.ts
lib/common/lib/utils.ts
export function addUserAgent(headers: Headers) {
const appendUserAgent = process.env.OCI_SDK_APPEND_USER_AGENT;
const clientInfo = `Oracle-TypeScriptSDK/${version}`;
// Check if the sdk is used in browser or node, populate header accordingly.
if (!isBrowser()) {
// Hash the values of Platform specific attributes
if (isEmpty(NODE_PLATFORM_HASH)) {
populatePlatformHash();
}
const platform = NODE_PLATFORM_HASH.get(PLATFORM_KEY);
const release = NODE_PLATFORM_HASH.get(RELEASE_KEY);
const nodeVersion = NODE_PLATFORM_HASH.get(VERSION_KEY);
// Formulate User-Agent
let userAgent = appendUserAgent
? `${clientInfo} (${platform}/${release}; Node/${nodeVersion}) ${appendUserAgent}`
: `${clientInfo} (${platform}/${release}; Node/${nodeVersion})`;
// Headers will always be replaced if they exist already
headers.append(USER_AGENT_HEADER, userAgent);
return;
}
headers.append(BROWSER_USER_AGENT_HEADER, clientInfo);
}
PR to follow
Metadata
Metadata
Assignees
Labels
No labels