mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
5f4c19da35
Co-authored-by: Opender Singh <opender.singh@konghq.com>
19 lines
536 B
TypeScript
19 lines
536 B
TypeScript
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;
|
|
}
|