Skip to content
File

Blob: src/workerd/api/tests/response-used-body-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
4import { rejects } from 'assert';
5 
6// Ported from the internal respond.ew-test
7 
8export const abortInternalStreamsTest = {
9 async test(_, env) {
10 await rejects(env.subrequest.fetch('http://example.org'), {
11 message: /Body has already been used/,
12 });
13 },
14};
15 
16export default {
17 async fetch() {
18 const enc = new TextEncoder();
19 const rs = new ReadableStream({
20 pull(c) {
21 c.enqueue(enc.encode('hello'));
22 },
23 });
24 const response = new Response(rs);
25 rs.cancel(new Error('boom'));
26 return response;
27 },
28};