mirror of
https://github.com/denoland/deno.git
synced 2025-01-18 11:53:59 -05:00
fetch: make body async iterable (#2563)
This commit is contained in:
parent
201ddd29a7
commit
988bcbb884
2 changed files with 15 additions and 0 deletions
|
@ -237,6 +237,10 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
|
||||||
tee(): [domTypes.ReadableStream, domTypes.ReadableStream] {
|
tee(): [domTypes.ReadableStream, domTypes.ReadableStream] {
|
||||||
return notImplemented();
|
return notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array> {
|
||||||
|
return io.toAsyncIterator(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Response implements domTypes.Response {
|
export class Response implements domTypes.Response {
|
||||||
|
|
|
@ -33,6 +33,17 @@ testPerm({ net: true }, async function fetchBlob(): Promise<void> {
|
||||||
assertEquals(blob.size, Number(headers.get("Content-Length")));
|
assertEquals(blob.size, Number(headers.get("Content-Length")));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testPerm({ net: true }, async function fetchAsyncIterator(): Promise<void> {
|
||||||
|
const response = await fetch("http://localhost:4545/package.json");
|
||||||
|
const headers = response.headers;
|
||||||
|
let total = 0;
|
||||||
|
for await (const chunk of response.body) {
|
||||||
|
total += chunk.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(total, Number(headers.get("Content-Length")));
|
||||||
|
});
|
||||||
|
|
||||||
testPerm({ net: true }, async function responseClone(): Promise<void> {
|
testPerm({ net: true }, async function responseClone(): Promise<void> {
|
||||||
const response = await fetch("http://localhost:4545/package.json");
|
const response = await fetch("http://localhost:4545/package.json");
|
||||||
const response1 = response.clone();
|
const response1 = response.clone();
|
||||||
|
|
Loading…
Add table
Reference in a new issue