Origin streams a ~10 MiB HTML report. This host injects one approved
script, strips standard HTML comments, and streams progressively without buffering the full body.
Key questions
Question
Does HTMLRewriter operate as a true streaming parser?
Yes. S2 returns rewriter.transform(originResponse).body directly and does not call text(), arrayBuffer(), or tee() on the hot path. This does not claim zero internal parser buffering.
Success criteria / proof
Complete report is transformed.The full response is delivered with one injected script, standard comments removed, and closing HTML intact.
Head fallback works.The normal document injects at the first <head>; a document without a head uses the body fallback.
Document-end fallback works.A fragment without head or body receives exactly one injected script at document end.
Streaming ownership is preserved.The Worker returns the HTMLRewriter body directly and does not buffer the report on the hot path.
Reset behavior is explicit.Origin or transform failure produces an error or truncated stream rather than a false completed response.