mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(flash): panic if response if undefined (#15964)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
This commit is contained in:
parent
2929ec9ffa
commit
35fe9ee530
2 changed files with 18 additions and 14 deletions
|
@ -1085,24 +1085,27 @@ Deno.test("upgradeHttpRaw tcp", async () => {
|
||||||
const promise2 = deferred();
|
const promise2 = deferred();
|
||||||
const ac = new AbortController();
|
const ac = new AbortController();
|
||||||
const signal = ac.signal;
|
const signal = ac.signal;
|
||||||
const handler = async (req: Request) => {
|
let conn: Deno.Conn;
|
||||||
const [conn, _] = Deno.upgradeHttpRaw(req);
|
let _head;
|
||||||
|
const handler = (req: Request) => {
|
||||||
|
[conn, _head] = Deno.upgradeHttpRaw(req);
|
||||||
|
|
||||||
await conn.write(
|
(async () => {
|
||||||
new TextEncoder().encode("HTTP/1.1 101 Switching Protocols\r\n\r\n"),
|
await conn.write(
|
||||||
);
|
new TextEncoder().encode("HTTP/1.1 101 Switching Protocols\r\n\r\n"),
|
||||||
|
);
|
||||||
|
|
||||||
promise.resolve();
|
promise.resolve();
|
||||||
|
|
||||||
const buf = new Uint8Array(1024);
|
const buf = new Uint8Array(1024);
|
||||||
const n = await conn.read(buf);
|
const n = await conn.read(buf);
|
||||||
|
|
||||||
assert(n != null);
|
assert(n != null);
|
||||||
const secondPacketText = new TextDecoder().decode(buf.slice(0, n));
|
const secondPacketText = new TextDecoder().decode(buf.slice(0, n));
|
||||||
assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n");
|
assertEquals(secondPacketText, "bla bla bla\nbla bla\nbla\n");
|
||||||
|
|
||||||
promise2.resolve();
|
promise2.resolve();
|
||||||
conn.close();
|
})();
|
||||||
};
|
};
|
||||||
const server = Deno.serve({
|
const server = Deno.serve({
|
||||||
// NOTE: `as any` is used to bypass type checking for the return value
|
// NOTE: `as any` is used to bypass type checking for the return value
|
||||||
|
@ -1131,6 +1134,7 @@ Deno.test("upgradeHttpRaw tcp", async () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
await promise2;
|
await promise2;
|
||||||
|
conn!.close();
|
||||||
tcpConn.close();
|
tcpConn.close();
|
||||||
|
|
||||||
ac.abort();
|
ac.abort();
|
||||||
|
|
|
@ -541,7 +541,7 @@
|
||||||
let resp;
|
let resp;
|
||||||
try {
|
try {
|
||||||
resp = handler(req);
|
resp = handler(req);
|
||||||
if (resp instanceof Promise || typeof resp.then === "function") {
|
if (resp instanceof Promise || typeof resp?.then === "function") {
|
||||||
resp.then((resp) =>
|
resp.then((resp) =>
|
||||||
handleResponse(
|
handleResponse(
|
||||||
req,
|
req,
|
||||||
|
|
Loading…
Reference in a new issue