summaryrefslogtreecommitdiff
path: root/extensions/fetch/22_body.js
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-06-23 16:00:23 +0200
committerGitHub <noreply@github.com>2021-06-23 16:00:23 +0200
commitedab21ebab3daa3cb0ebd5f6fca60c17098df242 (patch)
tree601557d2ff77687acc5b883201a7fbc0ce2482dd /extensions/fetch/22_body.js
parent2c4ce26f0bf1bf957d5c7dec28372898c60ed66c (diff)
fix(fetch): proxy body for requests created from other requests (#11093)
Additionally, if the existing `Request`'s body is disturbed, the Request creation should fail. This change also updates the step numbers in the Request constructor to match whatwg/fetch#1249.
Diffstat (limited to 'extensions/fetch/22_body.js')
-rw-r--r--extensions/fetch/22_body.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/extensions/fetch/22_body.js b/extensions/fetch/22_body.js
index 475af035f..9b5bf8eff 100644
--- a/extensions/fetch/22_body.js
+++ b/extensions/fetch/22_body.js
@@ -19,7 +19,7 @@
const { parseFormData, formDataFromEntries, formDataToBlob } =
globalThis.__bootstrap.formData;
const mimesniff = globalThis.__bootstrap.mimesniff;
- const { isReadableStreamDisturbed, errorReadableStream } =
+ const { isReadableStreamDisturbed, errorReadableStream, createProxy } =
globalThis.__bootstrap.streams;
class InnerBody {
@@ -133,6 +133,23 @@
second.length = this.length;
return second;
}
+
+ /**
+ * @returns {InnerBody}
+ */
+ createProxy() {
+ let proxyStreamOrStatic;
+ if (this.streamOrStatic instanceof ReadableStream) {
+ proxyStreamOrStatic = createProxy(this.streamOrStatic);
+ } else {
+ proxyStreamOrStatic = { ...this.streamOrStatic };
+ this.streamOrStatic.consumed = true;
+ }
+ const proxy = new InnerBody(proxyStreamOrStatic);
+ proxy.source = this.source;
+ proxy.length = this.length;
+ return proxy;
+ }
}
/**