tomas / tomas/needle

isEmpty is being placed in headers

Open
#269 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

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:
watcher

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at needle.js line 278 and inspect how options.headers is iterated and how config.headers is built; compare the referenced commit d227ef4205809084fe085d74f793813ec644f168 with the current behavior. Find a reproducible case or regression test showing that isEmpty must not become an HTTP header, then verify the request succeeds without the invalid header.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.