Skip to content

Commit

Permalink
fix(body): clone as sync instance
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgw committed Aug 28, 2019
1 parent 8582046 commit dd0b3c2
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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]
Expand Down

0 comments on commit dd0b3c2

Please sign in to comment.