diff options
-rw-r--r-- | src/config/chapath.nim | 2 | ||||
-rw-r--r-- | src/config/config.nim | 3 | ||||
-rw-r--r-- | src/loader/cgi.nim | 11 | ||||
-rw-r--r-- | src/loader/loader.nim | 3 |
4 files changed, 10 insertions, 9 deletions
diff --git a/src/config/chapath.nim b/src/config/chapath.nim index a2800c6c..adf852a0 100644 --- a/src/config/chapath.nim +++ b/src/config/chapath.nim @@ -9,7 +9,7 @@ import js/tojs import types/opt import utils/twtstr -const libexecPath* {.strdefine.} = "${%CHA_BIN_DIR}/../libexec/chawan" +const libexecPath {.strdefine.} = "${%CHA_BIN_DIR}/../libexec/chawan" type ChaPath* = distinct string diff --git a/src/config/config.nim b/src/config/config.nim index 634184d9..59cdad50 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -246,7 +246,8 @@ proc getBufferConfig*(config: Config, location: URL, cookiejar: CookieJar, proxy: proxy, cgiDir: cgiDir, urimethodmap: urimethodmap, - w3mCGICompat: config.external.w3m_cgi_compat + w3mCGICompat: config.external.w3m_cgi_compat, + libexecPath: ChaPath("${%CHA_LIBEXEC_DIR}").unquote().get ) ) diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim index 76076b1c..2a2451d2 100644 --- a/src/loader/cgi.nim +++ b/src/loader/cgi.nim @@ -4,7 +4,6 @@ import std/posix import std/streams import std/strutils -import config/chapath import extern/stdio import io/posixstream import loader/connecterror @@ -25,8 +24,8 @@ proc putMappedURL(url: URL) = putEnv("MAPPED_URI_PATH", url.path.serialize()) putEnv("MAPPED_URI_QUERY", url.query.get("")) -proc setupEnv(cmd, scriptName, pathInfo, requestURI: string, request: Request, - contentLen: int, prevURL: URL) = +proc setupEnv(cmd, scriptName, pathInfo, requestURI, libexecPath: string, + request: Request, contentLen: int, prevURL: URL) = let url = request.url putEnv("SERVER_SOFTWARE", "Chawan") putEnv("SERVER_PROTOCOL", "HTTP/1.0") @@ -132,7 +131,7 @@ proc handleLine(handle: LoaderHandle, line: string, headers: Headers) = headers.add(k, v) proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string], - prevURL: URL) = + libexecPath: string, prevURL: URL) = template t(body: untyped) = if not body: return @@ -210,8 +209,8 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string], else: closeStdin() # we leave stderr open, so it can be seen in the browser console - setupEnv(cmd, scriptName, pathInfo, requestURI, request, contentLen, - prevURL) + setupEnv(cmd, scriptName, pathInfo, requestURI, libexecPath, request, + contentLen, prevURL) discard execl(cstring(cmd), cstring(basename), nil) let code = int(ERROR_FAILED_TO_EXECUTE_CGI_SCRIPT) stdout.write("Cha-Control: ConnectionError " & $code) diff --git a/src/loader/loader.nim b/src/loader/loader.nim index de70c551..2fda709c 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -103,6 +103,7 @@ type cgiDir*: seq[string] uriMethodMap*: URIMethodMap w3mCGICompat*: bool + libexecPath*: string FetchPromise* = Promise[JSResult[Response]] @@ -133,7 +134,7 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) = redo = true continue if request.url.scheme == "cgi-bin": - handle.loadCGI(request, ctx.config.cgiDir, prevurl) + handle.loadCGI(request, ctx.config.cgiDir, ctx.config.libexecPath, prevurl) if handle.istream == nil: handle.close() else: |