diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-09-08 01:20:30 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-07 12:20:30 -0400 |
commit | a205e8a3c2bf5ba72fe18bd7f224303338956c62 (patch) | |
tree | 5f8f1af99c5429a69a351c22440b2d907de4720a /js/fetch.ts | |
parent | 8e3c879d1387d8b618904bf0bc8bc23e77a1114c (diff) |
fetch: implement bodyUsed (#2877)
Diffstat (limited to 'js/fetch.ts')
-rw-r--r-- | js/fetch.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/js/fetch.ts b/js/fetch.ts index d66eb1c48..0a5f793a8 100644 --- a/js/fetch.ts +++ b/js/fetch.ts @@ -35,7 +35,7 @@ function hasHeaderValueOf(s: string, value: string): boolean { } class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { - bodyUsed = false; + private _bodyUsed = false; private _bodyPromise: null | Promise<ArrayBuffer> = null; private _data: ArrayBuffer | null = null; readonly locked: boolean = false; // TODO @@ -223,6 +223,7 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { } read(p: Uint8Array): Promise<number | io.EOF> { + this._bodyUsed = true; return read(this.rid, p); } @@ -245,6 +246,10 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { [Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array> { return io.toAsyncIterator(this); } + + get bodyUsed(): boolean { + return this._bodyUsed; + } } export class Response implements domTypes.Response { @@ -252,7 +257,6 @@ export class Response implements domTypes.Response { readonly redirected: boolean; headers: domTypes.Headers; readonly trailer: Promise<domTypes.Headers>; - bodyUsed = false; readonly body: Body; constructor( @@ -302,6 +306,10 @@ export class Response implements domTypes.Response { return 200 <= this.status && this.status < 300; } + get bodyUsed(): boolean { + return this.body.bodyUsed; + } + clone(): domTypes.Response { if (this.bodyUsed) { throw new TypeError( |