tomas / needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.

Home Page:https://www.npmjs.com/package/needle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set Headers in needle.defaults() Results in Error Msg

andiMenge opened this issue · comments

Hi,
great http client but I need help figuring out an issue. I want to set some headers that should be send with all requests. So im using the defaults method to set them but the result is an error message.

Setup

lang: typescript@3.4.5, node.js@v11.15.0
types: @types/needle

Problem

Set the headers object in the defaults method results in the following error message

Error: Invalid property for defaults:headers

example

needle.defaults({
  accept: 'application/json',
  headers: {
    'X-AppId': myID,
    'X-AppSecret': mySecret,
    'X-ApiKey': myToken,
  },
});

Removing the headers object from the defaults methods like so works fine.

needle.defaults({
  accept: 'application/json',
});

nothing wrong with needle, it seams the the @types/needle are misleading.

Actually I think this happens because of the validation in defaults.

needle@2.4.0 still produces an error if trying to override default headers with needle.defaults()