brianleroux / tiny-json-http

:anchor: Minimalist HTTP client for JSON payloads.
172 stars 18 forks source link

Deep copy options passed in #19

Closed ryanblock closed 4 years ago

ryanblock commented 5 years ago

Tiny performs mutations on options passed in (such as headers); those options may be destructured from further up the prototype chain, and in doing so the mutation may have adverse impacts on unrelated operations completely outside the scope of tiny.

Suggest deep copying options before any mutations.

Repro steps:

let url = 'foo'
let headers = {'Accept': 'application/json'}
tiny.post({url, headers}, () => {
  console.log(headers) // will be mutated from the POST, and include such params as User-Agent, Content-Type, Content-Length, etc.
})