insomnia/packages/insomnia-app/app/network/basic-auth/get-header.ts

19 lines
536 B
TypeScript
Raw Normal View History

2018-06-25 17:42:50 +00:00
import type { RequestHeader } from '../../models/request';
export function getBasicAuthHeader(
username?: string | null,
password?: string | null,
encoding = 'utf8',
) {
const name = 'Authorization';
const header = `${username || ''}:${password || ''}`;
// @ts-expect-error -- TSCONVERSION appears to be a genuine error
const authString = Buffer.from(header, encoding).toString('base64');
const value = `Basic ${authString}`;
const requestHeader: RequestHeader = {
name,
value,
};
return requestHeader;
}