diff --git a/Deno/Library/Components/DenoHTTP.gcomp/DenoHTTP.gcomp b/Deno/Library/Components/DenoHTTP.gcomp/DenoHTTP.gcomp index 418fdfba..45b86430 100644 --- a/Deno/Library/Components/DenoHTTP.gcomp/DenoHTTP.gcomp +++ b/Deno/Library/Components/DenoHTTP.gcomp/DenoHTTP.gcomp @@ -1,5 +1,5 @@  - + @@ -24,12 +24,18 @@ - + + + + + + + @@ -41,10 +47,17 @@ + + + + + - - + + + + diff --git a/Deno/Library/Components/DenoHTTP.gcomp/HTTP Create Listeners.gvi b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Create Listeners.gvi new file mode 100644 index 00000000..048a73be --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Create Listeners.gvi @@ -0,0 +1,470 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "" + "" + "" + "" + "" + "" + "" + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error in + + + + + + error out + + + + + + hostname + + + + + + http listener references + + + + + + port + + + + + null + 0 + "" + + + + + null + + + + "" + "" + "" + "" + "" + "" + "" + "" + + + + + + + + + + + + + + hash + + + + + + hostname + + + + + + password + + + + + + pathname + + + + + + port + + + + + + protocol + + + + + + search + + + + + + username + + + + url pattern + + + + urlPatternConfigs + + + 0 + + + + port + + + "" + + + + hostname + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + url patterns + + + + + + + + + + + + + + + + + + + + False + 0 + "" + + + + + + + + + + False + 0 + "" + + + + + + + + null + + + + + + 8000 + + + 0.0.0.0 + + + null + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Listen for Request.gvi b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Serve Files.gvi similarity index 59% rename from Deno/Library/Components/DenoHTTP.gcomp/Listen for Request.gvi rename to Deno/Library/Components/DenoHTTP.gcomp/HTTP Serve Files.gvi index 25ec0108..a257df4e 100644 --- a/Deno/Library/Components/DenoHTTP.gcomp/Listen for Request.gvi +++ b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Serve Files.gvi @@ -1,5 +1,5 @@  - + @@ -8,120 +8,118 @@ - - - - - - - - - + + + + + + + - - - + + + - + - - + + - + - - - + + + + + + + + + - - - - - - + + + + + + - + - - - - - - + + + + + + - - - - - - + + - + + - - + + - - - - - - - - + + - - error out + + root path url - - + + + - - error in + + http listener reference - - - - - request listener - - - + + + - - request handler + + error in - - - - + + + - - done? + + error out - - + - - + + - + + "" + + + 0 + + + + + False @@ -133,7 +131,7 @@ - + False @@ -145,55 +143,50 @@ - - 0 - - - 0 - - - False - - - + + - + - - + + - + - - + + + + + + - - + + - - + + - + - + - + - + - + - + @@ -204,21 +197,24 @@ - - + + + + + + + + - - - - + @@ -226,7 +222,7 @@ - + diff --git a/Deno/Library/Components/DenoHTTP.gcomp/HTTP Wait On Listener.gvi b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Wait On Listener.gvi new file mode 100644 index 00000000..aa55cd51 --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Wait On Listener.gvi @@ -0,0 +1,515 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "" + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error out + + + + + + error in + + + + + + http connection reference + + + + + + + http listener reference + + + + + + + + + + + + + + + + + + + + + + + null + "" + "" + + + + + + + + + null + + + + "" + "" + + + + + + + + + + + + + + name + + + + + + value + + + + + headers + + + "" + + + + method + + + "" + + + + url + + + + http request + + + + + + + + + + + + + + + + + + headers + + + + + + + method + + + + + + + url + + + + + + + + + + + + + + + + + + + + + False + 0 + "" + + + + + + + + + + False + 0 + "" + + + + + + + + 0 + + + + + + 0 + + + + + + null + + + + + + "" + + + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Complete Request.gvi b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Write Response.gvi similarity index 79% rename from Deno/Library/Components/DenoHTTP.gcomp/Complete Request.gvi rename to Deno/Library/Components/DenoHTTP.gcomp/HTTP Write Response.gvi index c0a3dd46..0c7b24c9 100644 --- a/Deno/Library/Components/DenoHTTP.gcomp/Complete Request.gvi +++ b/Deno/Library/Components/DenoHTTP.gcomp/HTTP Write Response.gvi @@ -1,5 +1,5 @@  - + @@ -11,26 +11,25 @@ - - - - - - + + + + + - + - + - + @@ -58,16 +57,20 @@ - - + + + + + + - + - + @@ -92,13 +95,7 @@ error in - - - - - request handler - - + @@ -106,6 +103,12 @@ body + + + + + http connection reference + @@ -134,23 +137,26 @@ - - 0 - "" + + 0 + + + + - - + + - + - - + + @@ -158,15 +164,22 @@ - - + + + + + + + + + - + - + - + @@ -187,7 +200,10 @@ - + + + + diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Simple URL Pattern.gvi b/Deno/Library/Components/DenoHTTP.gcomp/Simple URL Pattern.gvi index 34b2f4e1..40c5b506 100644 --- a/Deno/Library/Components/DenoHTTP.gcomp/Simple URL Pattern.gvi +++ b/Deno/Library/Components/DenoHTTP.gcomp/Simple URL Pattern.gvi @@ -1,5 +1,5 @@  - + @@ -44,19 +44,33 @@ - + url pattern - + - + + + + + pathname + + + + + + search + + + + * @@ -74,82 +88,68 @@ - + * - + hash - + * - + hostname - + * - + password - + * - + pathname - + * - + port - + * - + protocol - + * - + search - + * - + username - + url pattern - - - - - - - pathname - - - - - - search - - - + + @@ -157,30 +157,30 @@ - + "" @@ -205,17 +205,17 @@ - - + + - - + + - + diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/DenoHTTP.jsli b/Deno/Library/Components/DenoHTTP.gcomp/Support/DenoHTTP.jsli index 668c9805..2677eea9 100644 --- a/Deno/Library/Components/DenoHTTP.gcomp/Support/DenoHTTP.jsli +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/DenoHTTP.jsli @@ -1,5 +1,5 @@  - + @@ -85,7 +85,7 @@ - + @@ -137,14 +137,14 @@ - - + + - + @@ -174,9 +174,9 @@ - + - + @@ -219,6 +219,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/header.gtype/header.gtype b/Deno/Library/Components/DenoHTTP.gcomp/Support/header.gtype/header.gtype new file mode 100644 index 00000000..b12b7fbe --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/header.gtype/header.gtype @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + "" + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/http connection reference.gtype/http connection reference.gtype b/Deno/Library/Components/DenoHTTP.gcomp/Support/http connection reference.gtype/http connection reference.gtype new file mode 100644 index 00000000..6e43fdfe --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/http connection reference.gtype/http connection reference.gtype @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/http listener reference.gtype/http listener reference.gtype b/Deno/Library/Components/DenoHTTP.gcomp/Support/http listener reference.gtype/http listener reference.gtype new file mode 100644 index 00000000..2797f1be --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/http listener reference.gtype/http listener reference.gtype @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/http request.gtype/http request.gtype b/Deno/Library/Components/DenoHTTP.gcomp/Support/http request.gtype/http request.gtype new file mode 100644 index 00000000..9db72dd9 --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/http request.gtype/http request.gtype @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + null + "" + "" + + + + + + + + + + + + + + + + + "" + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/http response.gtype/http response.gtype b/Deno/Library/Components/DenoHTTP.gcomp/Support/http response.gtype/http response.gtype new file mode 100644 index 00000000..6d2c5e6e --- /dev/null +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/http response.gtype/http response.gtype @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + 200 + "" + null + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoHTTP.gcomp/Support/url pattern.gtype/url pattern.gtype b/Deno/Library/Components/DenoHTTP.gcomp/Support/url pattern.gtype/url pattern.gtype index d18b24dd..aaf0e67f 100644 --- a/Deno/Library/Components/DenoHTTP.gcomp/Support/url pattern.gtype/url pattern.gtype +++ b/Deno/Library/Components/DenoHTTP.gcomp/Support/url pattern.gtype/url pattern.gtype @@ -1,5 +1,5 @@  - + @@ -7,13 +7,13 @@ - + - + "" @@ -33,7 +33,7 @@ - + @@ -51,13 +51,13 @@ - - + diff --git a/Deno/Library/Support/DenoHTTP/deno-http.ts b/Deno/Library/Support/DenoHTTP/deno-http.ts index 6800f2a0..5f239ac6 100644 --- a/Deno/Library/Support/DenoHTTP/deno-http.ts +++ b/Deno/Library/Support/DenoHTTP/deno-http.ts @@ -31,7 +31,7 @@ class HTTPConnection { class HTTPListener { private readonly streamController: ReadableStreamDefaultController; private readonly streamReader: ReadableStreamDefaultReader; - constructor(public readonly urlPattern: URLPattern, abortController: AbortController) { + constructor(private readonly urlPattern: URLPattern, abortController: AbortController) { let steamController: ReadableStreamDefaultController; const readableStream = new ReadableStream({ start: (controller) => { @@ -45,9 +45,16 @@ class HTTPListener { this.streamReader = readableStream.getReader(); } - public async waitForConnection (): Promise { + public shouldConnect (request: Request): boolean { + return this.urlPattern.test(request.url); + } + + public async waitForConnection (): Promise { const result = await this.streamReader.read(); - return result.done ? undefined : result.value; + if (result.done) { + throw new Error('Connection closed'); + } + return result.value; } public enqueueConnection (httpConnection: HTTPConnection): void { @@ -66,22 +73,30 @@ interface URLPatternConfig { username: string; } -const httpCreateListeners = function (urlPatternConfigsJSON: string): HTTPListener[] { - const urlPatternConfigs = JSON.parse(urlPatternConfigsJSON) as URLPatternConfig[]; +interface HTTPCreateListenersConfig { + urlPatternConfigs: URLPatternConfig[]; + port: number; + hostname: string; +} + +const httpCreateListeners = function (configJSON: string): HTTPListener[] { + const {urlPatternConfigs, port, hostname} = JSON.parse(configJSON) as HTTPCreateListenersConfig; const urlPatterns = urlPatternConfigs.map(urlPatternConfig => new URLPattern(urlPatternConfig)); const abortController = new AbortController(); const httpListeners = urlPatterns.map(urlPattern => new HTTPListener(urlPattern, abortController)); Deno.serve({ - signal: abortController.signal + signal: abortController.signal, + port, + hostname }, async (request: Request): Promise => { for (const httpListener of httpListeners) { - if (httpListener.urlPattern.test(request.url)) { + if (httpListener.shouldConnect(request)) { const httpConnection = new HTTPConnection(request); httpListener.enqueueConnection(httpConnection); return await httpConnection.waitForResponse(); } } - throw new Error('unhandled'); + throw new Error(`Unhandled request ${request.url}`); }); // TODO figure out returning the abort controller @@ -89,13 +104,9 @@ const httpCreateListeners = function (urlPatternConfigsJSON: string): HTTPListen return httpListeners; }; -const httpWaitOnListener = async function (httpListener: HTTPListener): Promise { +const httpWaitOnListener = async function (httpListener: HTTPListener): Promise { const httpConnection = await httpListener.waitForConnection(); - if (!httpConnection) { - return []; - } - - return [httpConnection]; + return httpConnection; }; @@ -103,8 +114,8 @@ const httpWriteResponse = function (httpConnection: HTTPConnection, body: string httpConnection.setResponse(new Response(body)); }; -const serveFileRequests = async function (httpListener: HTTPListener, serveRootUrl: string): Promise { - const fsRoot = fromFileUrl(serveRootUrl); +const httpServeFiles = async function (httpListener: HTTPListener, rootPathUrl: string): Promise { + const fsRoot = fromFileUrl(rootPathUrl); while(true) { const httpConnection = await httpListener.waitForConnection(); if (!httpConnection) { @@ -118,16 +129,22 @@ const serveFileRequests = async function (httpListener: HTTPListener, serveRootU } }; -const requestUrl = function (httpConnection: HTTPConnection) { - return httpConnection.request.url; +const httpConnectionGetRequest = function (httpConnection: HTTPConnection) { + const request = { + method: httpConnection.request.method, + url: httpConnection.request.url, + headers: [...httpConnection.request.headers.entries()].map(([name, value]) => ({name, value})), + }; + const requestJSON = JSON.stringify(request); + return requestJSON; }; const api = { httpCreateListeners, httpWaitOnListener, httpWriteResponse, - serveFileRequests, - requestUrl + httpServeFiles, + httpConnectionGetRequest } as const; declare namespace globalThis { diff --git a/Deno/Server.gcomp/main.gviweb b/Deno/Server.gcomp/main.gviweb index 43ccf45c..e0fbf0fd 100644 --- a/Deno/Server.gcomp/main.gviweb +++ b/Deno/Server.gcomp/main.gviweb @@ -1,5 +1,5 @@  - + @@ -36,25 +36,11 @@ - - - - - - - - - - - - - - - + - - - + + + @@ -64,15 +50,11 @@ - + - - - - - - - + + + @@ -82,7 +64,7 @@ - + /api/systemlink @@ -92,7 +74,7 @@ pathname - + @@ -118,53 +100,43 @@ arg - + - + - - + + + + - + - - + + + + - + - + - + - - - - - - - - - - - - - - - + @@ -182,10 +154,6 @@ - - - - tag-value @@ -194,7 +162,7 @@ key - + @@ -207,7 +175,7 @@ - + @@ -257,7 +225,7 @@ stop - + @@ -266,68 +234,52 @@ + + + - - - - - - - - - - - - - - - - * - - - - pathname - - - + - + - - + + + + - + - - + + + + - + - + - + - done iteration %d @@ -340,7 +292,7 @@ - + @@ -360,7 +312,7 @@ stop - + @@ -369,11 +321,12 @@ + - + @@ -383,7 +336,7 @@ - + /websocket @@ -393,8 +346,8 @@ pathname - - + + @@ -402,9 +355,9 @@ - - - + + + @@ -414,7 +367,7 @@ - + /api/systemlinkfile @@ -450,52 +403,42 @@ arg - + - + - - + + + + - + - - + + + + - + - + - + - - - - - - - - - - - - - - - + @@ -513,10 +456,7 @@ - - - - + file-value @@ -525,7 +465,7 @@ key - + @@ -552,7 +492,7 @@ - + @@ -588,7 +528,7 @@ stop - + @@ -598,10 +538,12 @@ + + - + @@ -638,33 +580,54 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + - - + + @@ -679,33 +642,34 @@ - - + + - - + + - + - - + + - - + - - + + + + + - @@ -735,15 +699,6 @@ - - - - - - - - - @@ -777,33 +732,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + @@ -816,7 +767,7 @@ - + @@ -824,8 +775,8 @@ - - + + @@ -853,12 +804,12 @@ - - + + - + - + @@ -866,14 +817,14 @@ - + - + - + - + @@ -881,54 +832,48 @@ - - - - - - - - - - - - - - - - - - - - + - + - + - + - - + + + + + + + + + + + + + + + - + - + - + - + - + - + @@ -1012,32 +957,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1132,25 +1051,78 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + - + @@ -1164,59 +1136,80 @@ + + + - - + + + + + - - + + - - + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1276,44 +1269,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - + @@ -1328,18 +1293,17 @@ - + - + - - - + + @@ -1349,7 +1313,6 @@ - @@ -1420,33 +1383,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1535,5 +1471,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file