isEmpty is being placed in headers
I found an issue where "isEmpty" is being written to the headers at line 278 in needle.js and does not happen 100% of the time. I am using the Node.js openwhisk package that calls needle for requests.
// now that all our headers are set, overwrite them if instructed.
for (var h in options.headers)
config.headers[h.toLowerCase()] = options.headers[h];
In issue #167 the above lines of code are committed as d227ef4205809084fe085d74f793813ec644f168
I am not really sure how to repro this without showing confidential code and using company resources, but I think it should be as simple as checking the property type before adding values from option.headers to config.headers?
option.headers contains 3 properties at this point in the code:
Authorization
User-Agent
x-namespace-id
config.headers contains 1 property:
accept
As the loop progresses, all 3 of the option.headers properties are written to config.headers, but on the next loop isEmpty is added to config.headers causing the request to fail with the following message:
"TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["isempty"]
at ClientRequest.setHeader (_http_outgoing.js:474:3)
at new ClientRequest (_http_client.js:184:14)
at Object.request (https.js:272:10)
at Needle.Object.<anonymous>.Needle.send_request (/MyProject/node_modules/needle/lib/needle.js:478:26)
at next (/MyProject/node_modules/needle/lib/needle.js:371:10)
at Needle.Object.<anonymous>.Needle.start (/MyProject/node_modules/needle/lib/needle.js:374:17)
at Function.Object.<anonymous>.module.exports.request (/MyProject/node_modules/needle/lib/needle.js:794:56)
at /MyProject/node_modules/needle/lib/needle.js:753:22
at new Promise (<anonymous>)
at Object.<anonymous>.module.exports (/MyProject/node_modules/needle/lib/needle.js:752:12)"
Watched Variables in the debugger at the 4th loop:

Hi @DrGirlfriend and thanks for reporting!
I guess we could add a hasOwnProperty check before inserting headers, but it looks like something else is getting in the middle here. How are you initializing or setting the options.headers object?
Ping @DrGirlfriend