diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-12 10:38:42 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-12 19:37:14 +0100 |
commit | 4eb57c2b88325d3963c6671a6f27bd08fc07cb59 (patch) | |
tree | 06bec584dcaf017d94e570e6cffb394b75aca338 /src/loader/loader.nim | |
parent | f779f672e6aa28efe03733226465c73c1a7490ad (diff) | |
download | chawan-4eb57c2b88325d3963c6671a6f27bd08fc07cb59.tar.gz |
local CGI: add mapped URI env vars; move about: to adapters
* Add MAPPED_URI_* as environment variables when a request is coming from urimethodmap It costs us compatibility with w3m, but it seems to be a massive improvement over smuggling in the URL as a query string and then writing an ad-hoc parser for every single urimethodmap script. The variables are set for every urimethodmap request, to avoid accidental leaking of global environment variables. * Move about: to adapters (an obvious improvement over the previous solution)
Diffstat (limited to 'src/loader/loader.nim')
-rw-r--r-- | src/loader/loader.nim | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 1f313a64..5fb49c07 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -28,7 +28,6 @@ import io/socketstream import io/urlfilter import js/error import js/javascript -import loader/about import loader/cgi import loader/connecterror import loader/curlhandle @@ -113,7 +112,8 @@ proc addFd(ctx: LoaderContext, fd: int, flags: int) = events: cast[cshort](flags) )) -const MaxRewrites = 2 # should be enough? TODO find out what w3m thinks +#TODO this may be too low if we want to use urimethodmap for everything +const MaxRewrites = 4 func canRewriteForCGICompat(ctx: LoaderContext, path: string): bool = if not ctx.config.w3mCGICompat: @@ -128,6 +128,7 @@ func canRewriteForCGICompat(ctx: LoaderContext, path: string): bool = proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) = var redo = true var tries = 0 + var prevurl: URL = nil while redo and tries < MaxRewrites: redo = false case request.url.scheme @@ -146,9 +147,6 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) = let handleData = handle.loadHttp(ctx.curlm, request) if handleData != nil: ctx.handleList.add(handleData) - of "about": - handle.loadAbout(request) - handle.close() of "data": handle.loadData(request) handle.close() @@ -161,9 +159,10 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) = if handleData != nil: ctx.handleList.add(handleData) of "cgi-bin": - handle.loadCGI(request, ctx.config.cgiDir) + handle.loadCGI(request, ctx.config.cgiDir, prevurl) handle.close() else: + prevurl = request.url case ctx.config.urimethodmap.findAndRewrite(request.url) of URI_RESULT_SUCCESS: inc tries |