-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consistent proxy auth handling (#146)
Extracts and reuses the `getBasic` helper function. Uses this helper to generate the `Basic` authentication header in the `proxy` hooks (before, this was done further down the line by [`http2-wrapper`](https://github.com/szmarczak/http2-wrapper), see the [related issue](szmarczak/http2-wrapper#108)).
- Loading branch information
Showing
7 changed files
with
43 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Returns the Basic auth string based on the `username` and `password` parts of the given URL. | ||
* If the URL does not contain neither username nor password, returns `null`. | ||
* @param url URL object to process | ||
* @returns `Basic BASE64` string | ||
*/ | ||
export function buildBasicAuthHeader(url: URL): string | null { | ||
if (!url.username && !url.password) { | ||
return null; | ||
} | ||
|
||
const username = decodeURIComponent(url.username ?? ''); | ||
const password = decodeURIComponent(url.password ?? ''); | ||
|
||
const basic = Buffer.from(`${username}:${password}`).toString('base64'); | ||
|
||
return `Basic ${basic}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters