-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Open
Description
Describe the bug
Currently, if we specify an empty proxy authorization, e.g. proxy.auth = {username: "", password: ""}, an unclear error message is thrown.
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
at new NodeError (node:internal/errors:399:5)
at Function.from (node:buffer:334:9)
at setProxy (file:///axios-with-empty-authn/node_modules/axios/lib/adapters/http.js:93:10)
at dispatchHttpRequest (file:///axios-with-empty-authn/node_modules/axios/lib/adapters/http.js:390:7)
at file:///axios-with-empty-authn/node_modules/axios/lib/adapters/http.js:142:5
at new Promise (<anonymous>)
at wrapAsync (file:///axios-with-empty-authn/node_modules/axios/lib/adapters/http.js:122:10)
at http (file:///axios-with-empty-authn/node_modules/axios/lib/adapters/http.js:148:10)
at Axios.dispatchRequest (file:///axios-with-empty-authn/node_modules/axios/lib/core/dispatchRequest.js:51:10)
at Axios.request (file:///axios-with-empty-authn/node_modules/axios/lib/core/Axios.js:142:33) {
code: 'ERR_INVALID_ARG_TYPE'
}
Seem this error happened from this PR: #4436
Lines 87 to 96 in 2e70cec
| if (proxy.auth) { | |
| // Support proxy auth object form | |
| if (proxy.auth.username || proxy.auth.password) { | |
| proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || ''); | |
| } | |
| const base64 = Buffer | |
| .from(proxy.auth, 'utf8') | |
| .toString('base64'); | |
| options.headers['Proxy-Authorization'] = 'Basic ' + base64; | |
| } |
The cause of the error is proxy.auth is still an object, not a string. Therefore, Buffer.from throws the error because It does not accept an object.
To Reproduce
Run the code snippet
Code snippet
// index.mjs
import axios from "axios";
const proxy = {
protocol: "http:",
host: "hostname.abc.xyz",
port: 3300,
auth: {
username: "",
password: "",
}
};
await axios.get("https://test-domain.abc", {proxy});Expected behavior
I'm not sure whether this is expected behavior or not. So, I suggest two options below
Expected behavior 01
Show a clear message about empty proxy authorization.
For example: Invalid proxy authorization
Expected behavior 02
Ignore the empty proxy authorization and skip the basic proxy authorization.
Axios Version
1.3.4
Adapter Version
No response
Browser
No response
Browser Version
No response
Node.js Version
18.14.2
OS
No response
Additional Library Versions
No response
Additional context/Screenshots
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels