mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(runtime/http): fix empty blob response (#10689)
This commit is contained in:
parent
25b784f00d
commit
7b1fd3d146
2 changed files with 29 additions and 4 deletions
|
@ -317,3 +317,25 @@ unitTest(
|
||||||
await promise;
|
await promise;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
unitTest(
|
||||||
|
{ perms: { net: true } },
|
||||||
|
async function httpServerEmptyBlobResponse() {
|
||||||
|
const promise = (async () => {
|
||||||
|
const listener = Deno.listen({ port: 4501 });
|
||||||
|
const conn = await listener.accept();
|
||||||
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
const event = await httpConn.nextRequest();
|
||||||
|
assert(event);
|
||||||
|
const { respondWith } = event;
|
||||||
|
await respondWith(new Response(new Blob([])));
|
||||||
|
httpConn.close();
|
||||||
|
listener.close();
|
||||||
|
})();
|
||||||
|
|
||||||
|
const resp = await fetch("http://127.0.0.1:4501/");
|
||||||
|
const respBody = await resp.text();
|
||||||
|
assertEquals("", respBody);
|
||||||
|
await promise;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
|
@ -132,10 +132,13 @@
|
||||||
} else {
|
} else {
|
||||||
const reader = innerResp.body.stream.getReader();
|
const reader = innerResp.body.stream.getReader();
|
||||||
const r1 = await reader.read();
|
const r1 = await reader.read();
|
||||||
if (r1.done) throw new TypeError("Unreachable");
|
if (r1.done) {
|
||||||
respBody = r1.value;
|
respBody = new Uint8Array(0);
|
||||||
const r2 = await reader.read();
|
} else {
|
||||||
if (!r2.done) throw new TypeError("Unreachable");
|
respBody = r1.value;
|
||||||
|
const r2 = await reader.read();
|
||||||
|
if (!r2.done) throw new TypeError("Unreachable");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
innerResp.body.streamOrStatic.consumed = true;
|
innerResp.body.streamOrStatic.consumed = true;
|
||||||
|
|
Loading…
Reference in a new issue