diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-02 02:10:22 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-02 02:10:22 +0100 |
commit | aafa670da29631be9d84c6090cf716291fd1bcbf (patch) | |
tree | 100cf718654e715df837fc21312a3ab6f1b33ccc /src/loader | |
parent | 6e420cc768e86ae15215e3600a7c66b54f4b42ff (diff) | |
download | chawan-aafa670da29631be9d84c6090cf716291fd1bcbf.tar.gz |
posixstream: add readLine implementation
slightly more efficient, but more importantly does not choke on NUL and weird \r\n
Diffstat (limited to 'src/loader')
-rw-r--r-- | src/loader/cgi.nim | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim index c266c0f6..d30f8fd1 100644 --- a/src/loader/cgi.nim +++ b/src/loader/cgi.nim @@ -232,8 +232,8 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string], # no data? handle.sendResult(ERROR_CGI_NO_DATA) return - let line = ps.readLine() - if line == "": #\r\n + var line: string + if not ps.readLine(line) or line == "": #\r\n # no headers, body comes immediately handle.sendResult(0) # success else: @@ -242,8 +242,7 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string], return var crlfFound = false while not ps.atEnd and res == RESULT_CONTROL_CONTINUE: - let line = ps.readLine() - if line == "": + if not ps.readLine(line) or line == "": # \r\n crlfFound = true break res = handle.handleControlLine(line, headers, status) @@ -251,8 +250,7 @@ proc loadCGI*(handle: LoaderHandle, request: Request, cgiDir: seq[string], return if not crlfFound: while not ps.atEnd: - let line = ps.readLine() - if line == "": #\r\n + if not ps.readLine(line) or line == "": # \r\n break handle.handleLine(line, headers) handle.sendStatus(status) |