New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Axios calling request setHeader with function as value #5055
Comments
I am having the same issue, had to do a work around by removing all invalid headers (using interceptor) before sending request. |
On Axios v0.27.2 that code logs: Timeout - RETRY 1
Timeout - RETRY 2
Timeout - RETRY 3
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
AxiosError: Nock: No match for request {
"method": "GET",
"url": "http://localhost/",
"headers": {
"accept": "application/json, text/plain, */*",
"user-agent": "axios/0.27.2" // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
} On Axios v1.1.3 with PR #5224 Timeout - RETRY 1
Timeout - RETRY 2
Timeout - RETRY 3
file:///H:/JS/forks/axios/lib/core/AxiosError.js:89
AxiosError.call(axiosError, error.message, code, config, request, response);
^
AxiosError: Nock: No match for request {
"method": "GET",
"url": "http://localhost/",
"headers": {
"accept": "application/json, text/plain, */*",
"user-agent": "axios/1.1.3", // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"accept-encoding": "gzip, deflate, br"
}
} It's hard to tell whether the issue is covered by the PR if the error is not reproducible on v0.27.2, but Axios will support an AxiosHeader instance as the headers config. |
@DigitalBrainJS I'm sorry. I had removed an actual URL in favour of a fake one so the successful call at the end never happened. Added another .get to the nock call above. |
@DigitalBrainJS Any chance of having a look at this with the revision I made? |
Describe the bug
Axios is calling request.setHeader with a function as the value and this is causing nock to throw an error. I see nothing in the NodeJS documentation saying that a function is a valid value for a header (I was guessing perhaps you could provide a function it would call but there is nothing in the docs to suggest that). As such, I'm starting with this as an Axios bug and not a deficiency in nock's implementation of Request.
It seems this is triggered by using axios-retry.
If, however, passing a function to request.setHeader is a valid thing, I'll close this and raise something on nock.
The function being passed to request.setHeader is the "get" method in the AxiosHeaders prototype.
The error returned by nock's request.setHeader is: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["0"]
To Reproduce
Expected behavior
It should get a timeout error twice and then receive and log an empty array.
Environment
The text was updated successfully, but these errors were encountered: