From dd0b3c2fefdfb1016b8d62a1583b34c6fbf3b636 Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Wed, 28 Aug 2019 15:08:29 +0200 Subject: [PATCH] fix(body): clone as sync instance --- index.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1eb9dc4..a6da83c 100644 --- a/index.js +++ b/index.js @@ -76,6 +76,24 @@ class Request extends _fetch.Request { defineBuffer(this, buffer) if (bodyError) defineBodyError(this, bodyError) } + + clone () { + checkBody(this) + return new Request(this.url, { + method: this.method, + headers: this.headers, + body: Buffer.from(this[_body]), + mode: this.mode, + credentials: this.credentials, + cache: this.cache, + redirect: this.redirect, + referrer: this.referrer, + referrerPolicy: this.referrerPolicy, + integrity: this.integrity, + keepalive: this.keepalive, + // signal: this.signal + }) + } } class Response extends _fetch.Response { @@ -85,6 +103,17 @@ class Response extends _fetch.Response { defineBuffer(this, buffer) if (bodyError) defineBodyError(this, bodyError) } + + clone () { + checkBody(this) + return new Response(Buffer.from(this[_body]), { + url: this.url, + headers: Array.from(this.headers), + status: this.status, + statusText: this.statusText, + counter: this.redirected ? 1 : 0 + }, this[_bodyError]) + } } class Body { @@ -95,12 +124,6 @@ class Body { } } - clone () { - const clone = _super(this, 'clone')() - defineBuffer(clone, Buffer.from(this[_body])) - return clone - } - arrayBuffer () { checkBody(this) const buf = this[_body]