| 1145 | }) |
| 1146 | |
| 1147 | function streamResponse(chunks: Uint8Array[], onCancel?: () => void): Response { |
| 1148 | let index = 0 |
| 1149 | const stream = new ReadableStream<Uint8Array>({ |
| 1150 | pull(controller) { |
| 1151 | if (index < chunks.length) { |
| 1152 | controller.enqueue(chunks[index++]) |
| 1153 | } else { |
| 1154 | controller.close() |
| 1155 | } |
| 1156 | }, |
| 1157 | cancel() { |
| 1158 | onCancel?.() |
| 1159 | }, |
| 1160 | }) |
| 1161 | return new Response(stream) |
| 1162 | } |
| 1163 | |
| 1164 | describe('readBodyWithLimit', () => { |
| 1165 | it('returns the full buffer when the streamed body is within the cap', async () => { |