Open cdaringe opened 5 months ago
Hi @cdaringe
This sounds indeed like a useful addition, however I'd like to keep the fetchToCurl function synchronous for now. And I assume that implementing this would require it to be async right?
However if we hide this feature behind a flag or configuration option it shouldn't break any code which relies on it returning the string immediately. Are you interested in opening a PR?
Best regards Leo
Yes to all!
So I started working on it, and i hit a few snags. I ended up wanting
fetchToCurl
)...that I just forked.
https://github.com/cdaringe/fetch-to-curl-ts
With that said, i'm happy to close the fork iff you're interested in the totality of the changes!
I just kinda got to hackin... and I either was gonna send you a massive PR, a wave a PRs, or this fork, and all were kinda overwhelming feeling (but i wanted stuff now)!
Sorry for the noise. Lemme know what you think.
-CD
I've not forgotten about this and will check it out :)
Problem
fetchToCurl(new Request(myUrl, { method: 'POST', body: someReadableStream })
doesn't work, and yields--data-binary={}
Discussion
It's easy to get into wanting this case when dealing with Request instances from common node tools. For example, I'm using
msw
, which... by the time a request is exiting the VM and you're in a proxy handler, body is converted to a stream just from node itself.Here's a dummy example of what we could do:
Then, rather than a naive
if (typeof body === 'object') { ... }
, we could first do aif (typeof req.body?.getReader === 'function) { ... }
and do the needful