zkat / make-fetch-happen

Get in loser, we're making requests!
Other
384 stars 27 forks source link

Update Redis cache example to prevent body used twice error #64

Closed athal7 closed 5 years ago

athal7 commented 5 years ago

Calling res.buffer() marks the body as having already been used, which makes subsequent parsing calls (e.g. res.json()) throw this error. By using a clone of the response for buffering / saving, the response's parse-ability is preserved to be consistent with a cache-miss response.

nikdo commented 5 years ago

This solution does not work for responses > 16Kb unfortunately.

nikdo commented 5 years ago

There is a PR in node-fetch repository that introduces highWaterMark parameter to clone method. It will fix the mentioned issue.

athal7 commented 5 years ago

Thanks @nikdo do you mind posting a link to that PR?

nikdo commented 5 years ago

Yeah. Sorry for omitting the link, I've just forgotten to add it there. This is the PR.

In the meantime, I realized @zkat is using her own fork of node-fetch. I'll create PR there too.

athal7 commented 5 years ago

Thanks @nikdo