Skip to content
File

Blob: src/workerd/api/tests/htmlrewriter-transform-cancel-test.js

javascript29 lines
1// Copyright (c) 2026 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4export const HtmlRewriterCancelBeforeRead = {
5 async test() {
6 for (let i = 0; i < 50; i++) {
7 const rewriter = new HTMLRewriter().on('div', {
8 element(element) {
9 element.setInnerContent('<span>x</span>', { html: true });
10 },
11 });
12 
13 const inputStream = new ReadableStream({
14 start(controller) {
15 controller.enqueue(
16 new TextEncoder().encode(
17 '<html><body><div>content</div></body></html>'
18 )
19 );
20 controller.close();
21 },
22 });
23 
24 const transformed = rewriter.transform(new Response(inputStream));
25 transformed.body.cancel();
26 }
27 },
28};