(username?: string | null, password?: string | null, encoding = 'utf8')
| 3 | import { bytesToBase64, latin1BytesFromString, utf8ToBase64 } from '~/common/utils/utf8-bytes'; |
| 4 | |
| 5 | export function getBasicAuthHeader(username?: string | null, password?: string | null, encoding = 'utf8') { |
| 6 | const name = 'Authorization'; |
| 7 | const header = `${username || ''}:${password || ''}`; |
| 8 | const authString = encoding === 'latin1' ? bytesToBase64(latin1BytesFromString(header)) : utf8ToBase64(header); |
| 9 | const value = `Basic ${authString}`; |
| 10 | const requestHeader: RequestHeader = { |
| 11 | name, |
| 12 | value, |
| 13 | }; |
| 14 | return requestHeader; |
| 15 | } |
no test coverage detected