leoek / fetch-to-curl

Convert javascript fetch requests to curl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle null and undefined headers

75lb opened this issue · comments

Handle null and undefined header values more gracefully..

Screenshot 2021-09-23 at 13 55 18

Thanks for reporting! Using headers with value null or undefined should indeed work like it does in the browser implementation of the fetch api.

Can you submit a PR with a testcase and the fix? Otherwise I'll try to include it in the next release myself, but I am not sure how soon that will be right now.

commented

Hi, I have a related question.
Shouldn't boolean headers be supported as well ? They work in node-fetch.
Btw thanks for the package, saved me some time!

Hi @DavidKrpt yes indeed, the goal was to replicate the request which would be executed by node-fetch or the fetch implementation of the browsers.

Therefore the expected output for fetchToCurl("https://github.com", { headers: { "x-test": null } }) should be curl 'https://github.com' -H "x-test: null" in my opinion.

Shouldn't boolean headers be supported as well ?

Good catch :) These also do not work properly right now. Since Browser just output the string true and false for booleans the same fix should be applied for them.

just for reference: potential fix in #37