How to fix "created multiple branches of a single stream" error?

I’m testing my Cloudflare Pages Functions on localhost with wrangler. I get this error message:

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 memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the request or response headers and metadata (e.g. in order to be able to modify them), use the appropriate constructors instead (for instance, new Response(response.body, response), new Request(request), etc).

The error happens when I include the following Function in my code, and call this function’s path from JavaScript on my website:

export async function onRequestPost(context) {
    try {
        const newUrl = new URL(context.request.url);
        // TODO in future: modify URL parameters here

        return await fetch(newUrl, context.request);
    } catch (err) {
        return new Response("Unaccepted.", {
            status: 400
        });
    }
}

I don’t see how this code is ‘creating multiple branches of a stream’. Can you point me out what I’m overlooking? Thanks! :slightly_smiling_face:


(I searched the error on the internet, in the forum, and asked Cursor AI and didn’t find info on how to fix it.)