Rewrite urls in the response body

I am looking to rewrite the domain of urls in the body of all responses before the are returned to the browser.
Currently I have:
var html = await response.text()
// fix paths in body
html = replaceDomainInResponse(html)
var newResponse = new Response(html, response, { })
return newResponse

But I think I am being caught out by responses that are returned in chunks? (the response body is corrupt) How can I achieve the same thing with the “streaming model”? Thanks so much in advance!
### Response Buffering
Enable or disable buffering of responses from the origin server
Requires Enterprise or higher

For modifying streaming html bodies, I’d recommend using the HTMLRewriter interface (released a few months after this question was posted). HTMLRewriter · Cloudflare Workers docs

Here is an example using HTMLRewriter to rewrite links: Rewrite links · Cloudflare Workers docs

I strongly agree with @taylorlee . I did several installations of this approach (meaning Html rewriting) and it works like a charm.