about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/localcgi.md10
-rw-r--r--src/loader/cgi.nim3
-rw-r--r--src/loader/connecterror.nim1
3 files changed, 8 insertions, 6 deletions
diff --git a/doc/localcgi.md b/doc/localcgi.md
index 1d46b3c6..2d15e6af 100644
--- a/doc/localcgi.md
+++ b/doc/localcgi.md
@@ -186,6 +186,11 @@ cgi-dir = "/usr/local/libexec/chawan/cgi-bin"
 
 and then put your script in `/usr/local/libexec/chawan/cgi-bin`.
 
+### My script is returning a "Failed to execute script" error message.
+
+This means the `execl` call to the script failed. Make sure that your CGI
+script's executable bit is set, i.e. run `chmod +x /path/to/cgi/script`.
+
 ### My script is returning an "invalid CGI path" error message.
 
 Make sure that you did not include leading slashes. Reminder:
@@ -203,11 +208,6 @@ so e.g. if your binary is in `~/src/chawan/target/release/bin/cha`, but you
 put your CGI script to `/usr/local/libexec/chawan/cgi-bin`, then it will
 not work.
 
-### My script returns a page saying "Failed to execute script".
-
-This means the `execl` call to the script failed. Make sure that your CGI
-script's executable bit is set, i.e. run `chmod +x /path/to/cgi/script`.
-
 ### My script is returning a "failed to set up CGI script" error message.
 
 This means that either `pipe` or `fork` failed. Something strange is going on
diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim
index dfe66e22..467e2087 100644
--- a/src/loader/cgi.nim
+++ b/src/loader/cgi.nim
@@ -211,7 +211,8 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string],
     setupEnv(cmd, scriptName, pathInfo, requestURI, request, contentLen,
       prevURL)
     discard execl(cstring(cmd), cstring(basename), nil)
-    stdout.write("Content-Type: text/plain\r\n\r\nFailed to execute script.")
+    let code = int(ERROR_FAILED_TO_EXECUTE_CGI_SCRIPT)
+    stdout.write("Cha-Control: ConnectionError " & $code)
     quit(1)
   else:
     discard close(pipefd[1]) # close write
diff --git a/src/loader/connecterror.nim b/src/loader/connecterror.nim
index acd4a28f..1b529128 100644
--- a/src/loader/connecterror.nim
+++ b/src/loader/connecterror.nim
@@ -1,4 +1,5 @@
 type ConnectErrorCode* = enum
+  ERROR_FAILED_TO_EXECUTE_CGI_SCRIPT = (-14, "failed to execute CGI script")
   ERROR_CGI_NO_DATA = (-13, "CGI script returned no data")
   ERROR_CGI_MALFORMED_HEADER = (-12, "CGI script returned a malformed header")
   ERROR_CGI_INVALID_CHA_CONTROL = (-11, "CGI got invalid Cha-Control header")