Merge pull request #18878 from calixteman/issue18876

Avoid exceptions in the console with ill-formed flate streams
This commit is contained in:
calixteman 2024-10-10 14:25:35 +02:00 committed by GitHub
commit 5f522d1c60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -161,8 +161,17 @@ class FlateStream extends DecodeStream {
try {
const { readable, writable } = new DecompressionStream("deflate");
const writer = writable.getWriter();
writer.write(bytes);
writer.close();
await writer.ready;
// We can't await writer.write() because it'll block until the reader
// starts which happens few lines below.
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
const chunks = [];
let totalLength = 0;

View File

@ -71,8 +71,14 @@ async function writeStream(stream, buffer, transform) {
try {
const cs = new CompressionStream("deflate");
const writer = cs.writable.getWriter();
writer.write(bytes);
writer.close();
await writer.ready;
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
// Response::text doesn't return the correct data.
const buf = await new Response(cs.readable).arrayBuffer();