insomnia/packages/insomnia-app/app/network/basic-auth/get-header.js
Julien Giovaresco 9d4390de2f
Introduce a checkbox in Basic Auth form to choose ISO-8859-1 encoding for credentials. (#2642)
Co-authored-by: Opender Singh <opender94@gmail.com>
2020-09-25 08:58:28 +12:00

16 lines
423 B
JavaScript

// @flow
import type { RequestHeader } from '../../models/request';
export function getBasicAuthHeader(
username: ?string,
password: ?string,
encoding: ?string = 'utf8',
): RequestHeader {
const name = 'Authorization';
const header = `${username || ''}:${password || ''}`;
const authString = Buffer.from(header, encoding).toString('base64');
const value = `Basic ${authString}`;
return { name, value };
}