mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
fix: unclear error message is thrown when specifying an empty proxy authorization (#6314)
* fix: add AxiosError to Invalid proxy authorization * fix: minor update * Update test/unit/adapters/http.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: remove redundant check Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: code style Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: style Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: correct assert Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: João Gabriel Quaresma de Almeida <joaoGabriel55> Co-authored-by: Jay <jasonsaayman@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -193,12 +193,16 @@ function setProxy(options, configProxy, location) {
|
||||
|
||||
if (proxy.auth) {
|
||||
// Support proxy auth object form
|
||||
if (proxy.auth.username || proxy.auth.password) {
|
||||
const validProxyAuth = Boolean(proxy.auth.username || proxy.auth.password);
|
||||
|
||||
if (validProxyAuth) {
|
||||
proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || '');
|
||||
} else if (typeof proxy.auth === 'object') {
|
||||
throw new AxiosError('Invalid proxy authorization', AxiosError.ERR_BAD_OPTION, { proxy });
|
||||
}
|
||||
const base64 = Buffer
|
||||
.from(proxy.auth, 'utf8')
|
||||
.toString('base64');
|
||||
|
||||
const base64 = Buffer.from(proxy.auth, 'utf8').toString('base64');
|
||||
|
||||
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user