Cloning the response twice generates a warning

Hey all, any chance this message is a false positive?
Your worker created multiple branches of a single stream (for instance, by calling `response.clone()` or `request.clone()`) but did not read the body of both branches. This is wasteful, as it forces the system to buffer the entire stream of data in (...)
Your worker created multiple branches of a single stream (for instance, by calling `response.clone()` or `request.clone()`) but did not read the body of both branches. This is wasteful, as it forces the system to buffer the entire stream of data in (...)
DEMO code to replicate the issue:
let response = await fetch(requestAsset);
let responseClone = response.clone();
let responseClone2 = response.clone();

await cache.put(newCacheKey, responseClone);
await cache.put(newCacheKey2, responseClone2);

return response;
let response = await fetch(requestAsset);
let responseClone = response.clone();
let responseClone2 = response.clone();

await cache.put(newCacheKey, responseClone);
await cache.put(newCacheKey2, responseClone2);

return response;
If I try to log the responseClone.bodyUsed and responseClone2.bodyUsed values, they both return true So I'm not really sure why the warning.
1 Reply
Register
Register11mo ago
Im getting this message too.
Want results from more Discord servers?
Add your server