-
-
Notifications
You must be signed in to change notification settings - Fork 733
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
Request headers have array values when using node-fetch #2197
Comments
I agree that something is fishy, but someone would need to dig into the code and find out why the current behavior is the way it is. Any help welcome! |
From a quick glance I think this is to support multiple values for a single header, RFC2616, section 4.2
And looking at node-fetch we can see that the internal representation is indeed an array: And looking at the nodejs api docs, it's perfectly valid for headers to be a list: https://nodejs.org/docs/latest/api/http.html#requestgetheadername So I guess an easy fix would be to check if the value is an array, do a Not had time to debug it to actually verify my claims, but this is what I've quickly looked up as I just hit the issue myself. |
Just created a test file given the supplied example and when debugging where node-fetch drops of the request it's clearly visible that the headers are passed as arrays: With |
I think you are right, thank you for digging into it. I think we also pass raw headers, which is entirely an array, so we might use comma-separated header values in For now I'd close this issue as "works as expected". But feel free to continue to comment |
Ahhh headers! This takes me back lol. It was headers that originally started my contributing to Nock. const http = require('http')
const req = http.request('http://example.com')
req.setHeader('X-Foo', false)
req.getHeaders() // this is how Nock sets `req.headers` for the Interceptor.
// [Object: null prototype] { host: 'example.com', 'x-foo': false } So, technically the types of the headers should be A decent argument would be that the header types should be updated to use |
What is the expected behavior?
The TypeScript type for req.headers says that each value is a string.
What is the actual behavior?
When calling with node-fetch, most values appear to be an array of strings. This is surprising to me because nock should be operating on a lower level and shouldn't care which library is making the request.
Possible solution
Don't know, haven't traced the code. If header value arrays are possible in any case, the type should at least be changed to
string | string[]
.How to reproduce the issue
Runkit: https://runkit.com/fluggo/nock-nock-2197
Does the bug have a test case?
Don't know
Versions
The text was updated successfully, but these errors were encountered: