mirror of
https://github.com/denoland/deno.git
synced 2025-10-01 14:41:15 +00:00
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:
parent
2c4ce26f0b
commit
edab21ebab
5 changed files with 45 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue