Skip to content

Browser detection removal #400

@AaronDabney

Description

@AaronDabney

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions