Skip to content

Commit

Permalink
Close connection when done
Browse files Browse the repository at this point in the history
Without this browsers like w3m are kept hanging.
  • Loading branch information
SyrupThinker committed Aug 2, 2020
1 parent 1fc40fd commit 97dd685
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/docuraptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,18 +1296,23 @@ async function handleStatic(req: ServerRequest): Promise<void> {
}

async function handler(req: ServerRequest): Promise<void> {
if (!["HEAD", "GET"].includes(req.method)) {
handleFail(req, 404, "Invalid method");
}
try {
if (!["HEAD", "GET"].includes(req.method)) {
handleFail(req, 404, "Invalid method");
}

if (req.url.startsWith(static_prefix)) {
await handleStatic(req);
} else if (req.url.startsWith(doc_prefix)) {
await handleDoc(req);
} else if (req.url === "/") {
await handleIndex(req);
} else {
await handleFail(req, 404, "Malformed path");
if (req.url.startsWith(static_prefix)) {
await handleStatic(req);
} else if (req.url.startsWith(doc_prefix)) {
await handleDoc(req);
} else if (req.url === "/") {
await handleIndex(req);
} else {
await handleFail(req, 404, "Malformed path");
}
} finally {
req.finalize();
req.conn.close();
}
}

Expand Down

0 comments on commit 97dd685

Please sign in to comment.