about summary refs log tree commit diff stats
path: root/src/loader
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-02 03:54:55 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-02 03:54:55 +0100
commit77e252b77463696880f1584890c2d95a6a34c377 (patch)
tree0565bf7431ba23773a2256d1d06cbb05cec12895 /src/loader
parentf955317b306308cf023239e7c790deb113ed1e67 (diff)
downloadchawan-77e252b77463696880f1584890c2d95a6a34c377.tar.gz
cgi: fix regression in header handling
it's a good idea to use the return value, but it must substitute atEnd.
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/cgi.nim13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim
index d30f8fd1..cb6e8ae4 100644
--- a/src/loader/cgi.nim
+++ b/src/loader/cgi.nim
@@ -233,7 +233,8 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string],
       handle.sendResult(ERROR_CGI_NO_DATA)
       return
     var line: string
-    if not ps.readLine(line) or line == "": #\r\n
+    var hasMore = ps.readLine(line)
+    if line == "": # \r\n or EOF
       # no headers, body comes immediately
       handle.sendResult(0) # success
     else:
@@ -241,16 +242,18 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string],
       if res == RESULT_ERROR:
         return
       var crlfFound = false
-      while not ps.atEnd and res == RESULT_CONTROL_CONTINUE:
-        if not ps.readLine(line) or line == "": # \r\n
+      while hasMore and res == RESULT_CONTROL_CONTINUE:
+        hasMore = ps.readLine(line)
+        if line == "": # \r\n
           crlfFound = true
           break
         res = handle.handleControlLine(line, headers, status)
         if res == RESULT_ERROR:
           return
       if not crlfFound:
-        while not ps.atEnd:
-          if not ps.readLine(line) or line == "": # \r\n
+        while hasMore:
+          hasMore = ps.readLine(line)
+          if line == "": # \r\n
             break
           handle.handleLine(line, headers)
     handle.sendStatus(status)