-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: clone methods correctly handle teeing body stream #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ class Request { | |
this.signal = request.signal; | ||
this.headers = new Headers(options.headers ?? request.headers); | ||
|
||
if (!options.body && request._body._bodyInit) { | ||
if (options.body === undefined && request._body._bodyInit) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to avoid explicit null body triggering this case I think |
||
this._body = new Body(request._body._bodyInit); | ||
request._body.bodyUsed = true; | ||
} | ||
|
@@ -85,7 +85,14 @@ class Request { | |
} | ||
|
||
clone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return new Request(this, { body: this._body._bodyInit }); | ||
if (this.bodyUsed) { | ||
throw new TypeError("Already read"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
const newRequest = new Request(this, { body: null }); | ||
newRequest._body = this._body.clone(); | ||
|
||
return newRequest; | ||
} | ||
|
||
blob() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,19 @@ class Response { | |
} | ||
|
||
clone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return new Response(this._body._bodyInit, { | ||
if (this.bodyUsed) { | ||
throw new TypeError("Already read"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
const newResponse = new Response(null, { | ||
status: this.status, | ||
statusText: this.statusText, | ||
headers: new Headers(this.headers), | ||
url: this.url, | ||
}); | ||
newResponse._body = this._body.clone(); | ||
|
||
return newResponse; | ||
} | ||
|
||
blob() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://fetch.spec.whatwg.org/#concept-body-clone