about summary refs log tree commit diff stats
path: root/src/loader/loader.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-30 02:51:13 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-30 03:07:15 +0200
commit8048a943706ee32f5970e461dda0a01aeb55c27f (patch)
treea9456532629274491e7ccfdc0b7773da247e58a1 /src/loader/loader.nim
parentef8124638b6b056a4721918b47fc00a349ab0da1 (diff)
downloadchawan-8048a943706ee32f5970e461dda0a01aeb55c27f.tar.gz
loader: add local-cgi
Add w3m-style local CGI support.

It is not quite as powerful as w3m's local CGI, because it lacks an
equivalent to W3m-control. Not sure if it's worth adding; we certainly
shouldn't allow passing JS in headers, but a custom language for
headers does not sound like a great idea either...

eh, idk. also, TODO add multipart
Diffstat (limited to 'src/loader/loader.nim')
-rw-r--r--src/loader/loader.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 6cd17f44..809219fe 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -29,6 +29,7 @@ import io/urlfilter
 import js/error
 import js/javascript
 import loader/about
+import loader/cgi
 import loader/connecterror
 import loader/curlhandle
 import loader/data
@@ -98,6 +99,7 @@ type
     # When set to false, requests with a proxy URL are overridden by the
     # loader proxy.
     acceptProxy*: bool
+    cgiDir*: seq[string]
 
   FetchPromise* = Promise[JSResult[Response]]
 
@@ -130,6 +132,9 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) =
     let handleData = handle.loadGopher(ctx.curlm, request)
     if handleData != nil:
       ctx.handleList.add(handleData)
+  of "cgi-bin":
+    handle.loadCGI(request, ctx.config.cgiDir)
+    handle.close()
   else:
     discard handle.sendResult(ERROR_UNKNOWN_SCHEME)
     handle.close()
@@ -201,7 +206,6 @@ proc acceptConnection(ctx: LoaderContext) =
       for fd in fds:
         ctx.handleMap.withValue(fd, handlep):
           handlep[].resume()
-
   except IOError:
     # End-of-file, broken pipe, or something else. For now we just
     # ignore it and pray nothing breaks.