export function prepareHeaders()

in src/connection/BaseConnection.ts [193:209]


export function prepareHeaders (headers: http.IncomingHttpHeaders = {}, auth?: BasicAuth | ApiKeyAuth | BearerAuth): http.IncomingHttpHeaders {
  if (auth != null && headers.authorization == null) {
    /* istanbul ignore else */
    if (isApiKeyAuth(auth)) {
      if (typeof auth.apiKey === 'object') {
        headers.authorization = 'ApiKey ' + Buffer.from(`${auth.apiKey.id}:${auth.apiKey.api_key}`).toString('base64')
      } else {
        headers.authorization = `ApiKey ${auth.apiKey}`
      }
    } else if (isBearerAuth(auth)) {
      headers.authorization = `Bearer ${auth.bearer}`
    } else if (auth.username != null && auth.password != null) {
      headers.authorization = 'Basic ' + Buffer.from(`${auth.username}:${auth.password}`).toString('base64')
    }
  }
  return headers
}