Caching POST requests works but shows warning in console
I'm using this guide to add caching of POST requests to my cloudflare worker:
https://developers.cloudflare.com/workers/examples/cache-post-request/
It seems to work, but it's showing warnings in console. For the line that corresponds to
const body = await request.clone().text();
, it's showing the following error:
Anyone know how to get rid of this warning?Cloudflare Docs
Cache POST requests Ā· Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones ā¦
5 Replies
Hi :meowwave: do you do something with the uncloned request?
This warning comes up when you clone a request/response but don't simultaneously drain both bodies
Hi! Yes, the original (uncloned) request is later accessed with
await request.json();
Hmm, the only time I was able to reproduce is when I didn't read one of the two, or read them strictly one after another
ah so if there's a slight delay in reading one of them the warning may be shown? is it safe to ignore the warning if I'm sure both are being read?
That's... interesting. I'm facing the same issue, now. š¤
----
[wrangler:inf] GET / 200 OK (1249ms)
newResponse Body Used: true
A ReadableStream branch was created but never consumed. Such branches can be created, for instance, by calling the tee() method on a ReadableStream, or by calling the clone() method on a Request or Response object. If a branch is created but never consumed, it can force the runtime to buffer the entire body of the stream in memory, which may cause the Worker to exceed its memory limit and be terminated. To avoid this, ensure that all branches created are consumed.
š