summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-03-16 06:36:05 -0300
committerEuAndreh <eu@euandre.org>2024-03-16 06:36:05 -0300
commitcac533d1cc73ccd2659beb87c146254ed2887c9b (patch)
tree72dec38a2f65c0814ed14fb401c97dbebe54df53 /src
parentsrc/hero.mjs: findHandler(): learn how to find upgrade routes (diff)
downloadpapod-cac533d1cc73ccd2659beb87c146254ed2887c9b.tar.gz
papod-cac533d1cc73ccd2659beb87c146254ed2887c9b.tar.xz
src/hero.mjs: Remove current makeUpgradeListener() and its helpers
Diffstat (limited to 'src')
-rw-r--r--src/hero.mjs61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/hero.mjs b/src/hero.mjs
index 7483a21..b47d459 100644
--- a/src/hero.mjs
+++ b/src/hero.mjs
@@ -415,67 +415,6 @@ export const handleRequest = async (table, reqHandle) => {
return await handlerFn(request);
};
-export const emitHeaders = obj =>
- Object.keys(obj)
- .sort(u.strSortFn)
- .map(name => `${name}: ${obj[name]}`)
- .join("\r\n");
-
-const STATUS_CODES = {
- 404: "Not Found",
- 405: "Method Not Allowed",
-};
-
-export const buildHttpPayload = (code, {
- headers = {},
- message = `${STATUS_CODES[code]}\n`,
-} = {}) =>
- `HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
- emitHeaders({
- "Connection": "close",
- "Content-Type": "text/plain; charset=UTF-8",
- "Content-Length": Buffer.byteLength(message),
- ...headers,
- }) +
- "\r\n\r\n" +
- message;
-
-export const fallback404Handler = (_req, socket) =>
- socket.end(buildHttpPayload(404)).destroySoon();
-
-export const fallback405Handler = (_req, socket) =>
- socket.end(buildHttpPayload(405)).destroySoon();
-
-export const handlerForConnection = (table, method, path) => {
- if (method !== WEBSOCKET_METHOD) {
- return fallback405Handler;
- }
-
- const segments = pathToSegments(path);
- const handlerFn = u.getIn(table, [WEBSOCKET_KEYWORD, WEBSOCKET_METHOD].concat(segments));
- return handlerFn || fallback404Handler;
-};
-
-export const makeUpgradeListener = table => async (req, socket, _head) => {
- const { method, url, headers } = req;
- const [ path, queryParams ] = url.split("?");
- const handlerFn = handlerForConnection(table, method, path);
-
- const request = {
- params: {
- path: {},
- query: extractQueryParams(queryParams),
- },
- method,
- path,
- headers,
- handler: handlerFn,
- ref: req,
- };
-
- return await handlerFn(request, socket);
-};
-
export const makeRequestListener = table => async (req, res) => {
const { status, headers, body } = await handleRequest(table, {
...req,