diff options
author | bptato <nincsnevem662@gmail.com> | 2022-08-18 21:08:29 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-08-18 21:08:29 +0200 |
commit | 6a990cef8eac9bf11d785d942873f9a5fa614585 (patch) | |
tree | 75315119c5787d89b1d0ee4512d445a19d18c068 /src/io/loader.nim | |
parent | 7a4faea7e046a65b2feeea6b2e08254a15eaef4c (diff) | |
download | chawan-6a990cef8eac9bf11d785d942873f9a5fa614585.tar.gz |
Fix request error handling
Diffstat (limited to 'src/io/loader.nim')
-rw-r--r-- | src/io/loader.nim | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim index 1fb6e7b7..4adf64bc 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -41,12 +41,10 @@ proc loadFile(url: Url, ostream: Stream) = let path = url.path.serialize_unicode() let istream = newFileStream(path, fmRead) if istream == nil: - ostream.swrite(404) # file not found - ostream.swrite("") - ostream.swrite(none(Url)) - ostream.swrite("") + ostream.swrite(1) ostream.flush() else: + ostream.swrite(0) ostream.swrite(200) # ok ostream.swrite(guessContentType(path)) ostream.swrite(none(Url)) @@ -98,10 +96,12 @@ proc doRequest*(loader: FileLoader, request: Request): LoadResult = if loader.istream != nil: loader.istream.swrite(request) loader.istream.flush() - loader.ostream.sread(result.status) - loader.ostream.sread(result.contenttype) - loader.ostream.sread(result.redirect) - result.s = loader.ostream + loader.ostream.sread(result.res) + if result.res == 0: + loader.ostream.sread(result.status) + loader.ostream.sread(result.contenttype) + loader.ostream.sread(result.redirect) + result.s = loader.ostream else: eprint "Error: no loader process" quit(1) @@ -147,6 +147,3 @@ proc newFileLoader*(defaultHeaders: HeaderList): FileLoader = proc newFileLoader*(): FileLoader = newFileLoader(DefaultHeaders) - -proc getPage*(loader: FileLoader, request: Request): LoadResult = - loader.doRequest(request) |