1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00

fix(ext/fetch): don't throw when bodyUsed inspect after upgrade (#27088)

Fixes https://github.com/denoland/deno/issues/27083
This commit is contained in:
Divy Srivastava 2024-11-26 08:08:46 -08:00 committed by GitHub
parent 3a55b67815
commit 93bbbe4184
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 59 additions and 2 deletions

View file

@ -286,8 +286,13 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
*/
get() {
webidl.assertBranded(this, prototype);
if (this[bodySymbol] !== null) {
return this[bodySymbol].consumed();
try {
if (this[bodySymbol] !== null) {
return this[bodySymbol].consumed();
}
} catch (_) {
// Request is closed.
return true;
}
return false;
},

View file

@ -4327,3 +4327,55 @@ Deno.test({
await server.shutdown();
});
// https://github.com/denoland/deno/issues/27083
Deno.test(
{ permissions: { net: true } },
async function httpServerWebSocketInspectRequest() {
const ac = new AbortController();
const listeningDeferred = Promise.withResolvers<void>();
const doneDeferred = Promise.withResolvers<void>();
const server = Deno.serve({
handler: (request) => {
const {
response,
socket,
} = Deno.upgradeWebSocket(request);
socket.onopen = () => {
Deno.inspect(request); // should not throw
};
socket.onerror = (e) => {
console.error(e);
fail();
};
socket.onmessage = (m) => {
socket.send(m.data);
socket.close(1001);
};
socket.onclose = () => doneDeferred.resolve();
return response;
},
port: servePort,
signal: ac.signal,
onListen: onListen(listeningDeferred.resolve),
onError: createOnErrorCb(ac),
});
await listeningDeferred.promise;
const def = Promise.withResolvers<void>();
const ws = new WebSocket(`ws://localhost:${servePort}`);
ws.onmessage = (m) => assertEquals(m.data, "foo");
ws.onerror = (e) => {
console.error(e);
fail();
};
ws.onclose = () => def.resolve();
ws.onopen = () => ws.send("foo");
await def.promise;
await doneDeferred.promise;
ac.abort();
await server.finished;
},
);