mirror of
https://github.com/denoland/deno.git
synced 2025-01-12 00:54:02 -05:00
fix(ext/fetch): Body#bodyUsed
for static body (#16080)
This fixes a bug where `Body#bodyUsed` incorrectly returns `false` for a body that has actually already been consumed, after `Body#body` is called.
This commit is contained in:
parent
15ea624790
commit
927f4e2e83
3 changed files with 24 additions and 0 deletions
|
@ -90,3 +90,13 @@ Deno.test(function customInspectFunction() {
|
||||||
);
|
);
|
||||||
assertStringIncludes(Deno.inspect(Response.prototype), "Response");
|
assertStringIncludes(Deno.inspect(Response.prototype), "Response");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(async function responseBodyUsed() {
|
||||||
|
const response = new Response("body");
|
||||||
|
assert(!response.bodyUsed);
|
||||||
|
await response.text();
|
||||||
|
assert(response.bodyUsed);
|
||||||
|
// .body getter is needed so we can test the faulty code path
|
||||||
|
response.body;
|
||||||
|
assert(response.bodyUsed);
|
||||||
|
});
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
const {
|
const {
|
||||||
isReadableStreamDisturbed,
|
isReadableStreamDisturbed,
|
||||||
errorReadableStream,
|
errorReadableStream,
|
||||||
|
readableStreamClose,
|
||||||
|
readableStreamDisturb,
|
||||||
createProxy,
|
createProxy,
|
||||||
ReadableStreamPrototype,
|
ReadableStreamPrototype,
|
||||||
} = globalThis.__bootstrap.streams;
|
} = globalThis.__bootstrap.streams;
|
||||||
|
@ -92,6 +94,8 @@
|
||||||
if (consumed) {
|
if (consumed) {
|
||||||
this.streamOrStatic = new ReadableStream();
|
this.streamOrStatic = new ReadableStream();
|
||||||
this.streamOrStatic.getReader();
|
this.streamOrStatic.getReader();
|
||||||
|
readableStreamDisturb(this.streamOrStatic);
|
||||||
|
readableStreamClose(this.streamOrStatic);
|
||||||
} else {
|
} else {
|
||||||
this.streamOrStatic = new ReadableStream({
|
this.streamOrStatic = new ReadableStream({
|
||||||
start(controller) {
|
start(controller) {
|
||||||
|
|
|
@ -1153,6 +1153,15 @@
|
||||||
reader[_closedPromise].resolve(undefined);
|
reader[_closedPromise].resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template R
|
||||||
|
* @param {ReadableStream<R>} stream
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function readableStreamDisturb(stream) {
|
||||||
|
stream[_disturbed] = true;
|
||||||
|
}
|
||||||
|
|
||||||
/** @param {ReadableStreamDefaultController<any>} controller */
|
/** @param {ReadableStreamDefaultController<any>} controller */
|
||||||
function readableStreamDefaultControllerCallPullIfNeeded(controller) {
|
function readableStreamDefaultControllerCallPullIfNeeded(controller) {
|
||||||
const shouldPull = readableStreamDefaultcontrollerShouldCallPull(
|
const shouldPull = readableStreamDefaultcontrollerShouldCallPull(
|
||||||
|
@ -5910,6 +5919,7 @@
|
||||||
createProxy,
|
createProxy,
|
||||||
writableStreamClose,
|
writableStreamClose,
|
||||||
readableStreamClose,
|
readableStreamClose,
|
||||||
|
readableStreamDisturb,
|
||||||
readableStreamForRid,
|
readableStreamForRid,
|
||||||
getReadableStreamRid,
|
getReadableStreamRid,
|
||||||
Deferred,
|
Deferred,
|
||||||
|
|
Loading…
Reference in a new issue