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.
This commit is contained in:
Andreu Botella 2021-06-23 16:00:23 +02:00 committed by GitHub
parent 2c4ce26f0b
commit edab21ebab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 19 deletions

View file

@ -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;
}
}
/**