diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-14 21:55:18 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-14 21:56:43 +0100 |
commit | fefdfbaa68762f9f154b00f54b99e14e259160b5 (patch) | |
tree | 2f039751552322167838219e2f4a87479c63cfa1 /src | |
parent | d26766c4c4015990703e84e8136f96d222edbc97 (diff) | |
download | chawan-fefdfbaa68762f9f154b00f54b99e14e259160b5.tar.gz |
cgi: fix broken pipe handling
if the socket is closed before the loader could send all header data, we must destroy the parser to avoid sending a result twice.
Diffstat (limited to 'src')
-rw-r--r-- | src/loader/cgi.nim | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim index b91e3b1b..6decb7b6 100644 --- a/src/loader/cgi.nim +++ b/src/loader/cgi.nim @@ -240,7 +240,7 @@ proc killHandle(handle: LoaderHandle) = discard handle.output.ostream.sendData(msg) handle.parser = nil -proc parseHeaders*(handle: LoaderHandle; buffer: LoaderBuffer): int = +proc parseHeaders0(handle: LoaderHandle; buffer: LoaderBuffer): int = let parser = handle.parser var s = parser.lineBuffer let L = if buffer == nil: 1 else: buffer.len @@ -287,5 +287,12 @@ proc parseHeaders*(handle: LoaderHandle; buffer: LoaderBuffer): int = parser.lineBuffer = s return L +proc parseHeaders*(handle: LoaderHandle; buffer: LoaderBuffer): int = + try: + return handle.parseHeaders0(buffer) + except ErrorBrokenPipe: + handle.parser = nil + return -1 + proc finishParse*(handle: LoaderHandle) = discard handle.parseHeaders(nil) |