diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-08 17:39:14 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-08 17:39:14 +0100 |
commit | 250cbcfaf6cb57b152659fb9e3c195ef4938adae (patch) | |
tree | a653218afce946867f3a8ff644cd372c25d90ad4 /src/loader/loader.nim | |
parent | cc9ac4d12c1f38029c640ac60fe38a220befa61b (diff) | |
download | chawan-250cbcfaf6cb57b152659fb9e3c195ef4938adae.tar.gz |
loader: fix eagain in fetch, only add URL to handle in debug
* eagain was causing fetch to add unnecessary null bytes to input streams * URL is now only added to handles in debug mode
Diffstat (limited to 'src/loader/loader.nim')
-rw-r--r-- | src/loader/loader.nim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 749f7d29..ada37648 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -166,7 +166,9 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) = proc onLoad(ctx: LoaderContext, stream: SocketStream) = var request: Request stream.sread(request) - let handle = newLoaderHandle(stream, request.canredir, request.url) + let handle = newLoaderHandle(stream, request.canredir) + when defined(debug): + handle.url = request.url if not ctx.config.filter.match(request.url): handle.sendResult(ERROR_DISALLOWED_URL) handle.close() @@ -512,14 +514,15 @@ proc onRead*(loader: FileLoader, fd: int) = loader.ongoing.withValue(fd, buffer): let response = buffer[].response while not response.body.atEnd(): + let olen = buffer[].buf.len try: - let olen = buffer[].buf.len buffer[].buf.setLen(olen + BufferSize) let n = response.body.readData(addr buffer[].buf[olen], BufferSize) buffer[].buf.setLen(olen + n) if n == 0: break except ErrorAgain, ErrorWouldBlock: + buffer[].buf.setLen(olen) break if response.body.atEnd(): buffer[].bodyRead.resolve(buffer[].buf) |