mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix(ext/fetch): clone second branch chunks in Body.clone() (#20057)
This PR makes `Body.clone()` spec compliant: https://fetch.spec.whatwg.org/#concept-body-clone > 1, Let « out1, out2 » be the result of [teeing](https://streams.spec.whatwg.org/#readablestream-tee) body’s [stream](https://fetch.spec.whatwg.org/#concept-body-stream). > ... > To tee a [ReadableStream](https://streams.spec.whatwg.org/#readablestream) stream, return ? [ReadableStreamTee](https://streams.spec.whatwg.org/#readable-stream-tee)(stream, true). --- Closes #10994
This commit is contained in:
parent
6a5b02bc79
commit
7895d154c3
3 changed files with 23 additions and 33 deletions
|
@ -33,6 +33,7 @@ import {
|
|||
readableStreamCollectIntoUint8Array,
|
||||
readableStreamDisturb,
|
||||
ReadableStreamPrototype,
|
||||
readableStreamTee,
|
||||
readableStreamThrowIfErrored,
|
||||
} from "ext:deno_web/06_streams.js";
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
|
@ -194,7 +195,7 @@ class InnerBody {
|
|||
* @returns {InnerBody}
|
||||
*/
|
||||
clone() {
|
||||
const { 0: out1, 1: out2 } = this.stream.tee();
|
||||
const { 0: out1, 1: out2 } = readableStreamTee(this.stream, true);
|
||||
this.streamOrStatic = out1;
|
||||
const second = new InnerBody(out2);
|
||||
second.source = core.deserialize(core.serialize(this.source));
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
const core = globalThis.Deno.core;
|
||||
const ops = core.ops;
|
||||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
import { structuredClone } from "ext:deno_web/02_structured_clone.js";
|
||||
import {
|
||||
AbortSignalPrototype,
|
||||
add,
|
||||
|
@ -2847,9 +2848,24 @@ function readableStreamDefaultTee(stream, cloneForBranch2) {
|
|||
queueMicrotask(() => {
|
||||
readAgain = false;
|
||||
const value1 = value;
|
||||
const value2 = value;
|
||||
let value2 = value;
|
||||
|
||||
// TODO(lucacasonato): respect clonedForBranch2.
|
||||
if (canceled2 === false && cloneForBranch2 === true) {
|
||||
try {
|
||||
value2 = structuredClone(value2);
|
||||
} catch (cloneError) {
|
||||
readableStreamDefaultControllerError(
|
||||
branch1[_controller],
|
||||
cloneError,
|
||||
);
|
||||
readableStreamDefaultControllerError(
|
||||
branch2[_controller],
|
||||
cloneError,
|
||||
);
|
||||
cancelPromise.resolve(readableStreamCancel(stream, cloneError));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (canceled1 === false) {
|
||||
readableStreamDefaultControllerEnqueue(
|
||||
|
@ -6464,6 +6480,7 @@ export {
|
|||
readableStreamForRidUnrefableRef,
|
||||
readableStreamForRidUnrefableUnref,
|
||||
ReadableStreamPrototype,
|
||||
readableStreamTee,
|
||||
readableStreamThrowIfErrored,
|
||||
TransformStream,
|
||||
TransformStreamDefaultController,
|
||||
|
|
|
@ -4382,36 +4382,8 @@
|
|||
"response-from-stream.any.worker.html": true,
|
||||
"response-cancel-stream.any.html": true,
|
||||
"response-cancel-stream.any.worker.html": true,
|
||||
"response-clone.any.html": [
|
||||
"Check response clone use structureClone for teed ReadableStreams (Int8Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Int16Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Int32Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (ArrayBufferchunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint8Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint8ClampedArraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint16Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint32Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (BigInt64Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (BigUint64Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Float32Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Float64Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (DataViewchunk)"
|
||||
],
|
||||
"response-clone.any.worker.html": [
|
||||
"Check response clone use structureClone for teed ReadableStreams (Int8Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Int16Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Int32Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (ArrayBufferchunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint8Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint8ClampedArraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint16Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Uint32Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (BigInt64Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (BigUint64Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Float32Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (Float64Arraychunk)",
|
||||
"Check response clone use structureClone for teed ReadableStreams (DataViewchunk)"
|
||||
],
|
||||
"response-clone.any.html": true,
|
||||
"response-clone.any.worker.html": true,
|
||||
"response-consume-empty.any.html": [
|
||||
"Consume empty FormData response body as text"
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue