Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ext/fetch/22_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/serve_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
);