cloudflare / cloudflare/html-rewriter-wasm

Feature request: inject streams into streams

Open
#12 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
219
Forks
20
PR merge metrics
No merged PRs in 30d

Description

Right now it seems like if we want to inject some content from a sub request we would use an async handler like so:

```javascript
async element(e) {
const response = await fetch(url); // make sub request
const text = await response.text(); // whole text buffered in memor, this blocks from sending more data until we get full response
e.append(text); // insert text into main content
}
```

But isn't this sort of wasteful a bit, I mean we are needing to buffer the whole subrequest in memory and need to wait for the whole response to finish.
Wouldn't it be better if the rewritter would support something like this:

```javascript
async element(e) {
const response = await fetch(url); // make sub request
e.append(response.body); // if stream provided it is correctly injected and streamed
}
```

In this case we will be returning the sub requests chunks as soon as they come and won't buffer them fully in memory.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.