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 | |
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')
-rw-r--r-- | src/loader/loader.nim | 7 | ||||
-rw-r--r-- | src/loader/loaderhandle.nim | 12 |
2 files changed, 12 insertions, 7 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) diff --git a/src/loader/loaderhandle.nim b/src/loader/loaderhandle.nim index 5d2dee4e..06149e23 100644 --- a/src/loader/loaderhandle.nim +++ b/src/loader/loaderhandle.nim @@ -8,7 +8,9 @@ import io/serialize import io/socketstream import loader/headers -import types/url +when defined(debug): + import types/url + type LoaderBufferPage = array[4056, uint8] # 4096 - 8 - 32 @@ -32,15 +34,15 @@ type currentBuffer*: LoaderBuffer currentBufferIdx*: int buffers: Deque[LoaderBuffer] - url*: URL #TODO TODO TODO debug + when defined(debug): + url*: URL # Create a new loader handle, with the output stream ostream. -proc newLoaderHandle*(ostream: PosixStream, canredir: bool, url: URL): LoaderHandle = +proc newLoaderHandle*(ostream: PosixStream, canredir: bool): LoaderHandle = return LoaderHandle( ostream: ostream, canredir: canredir, - fd: int(SocketStream(ostream).source.getFd()), - url: url + fd: int(SocketStream(ostream).source.getFd()) ) func `[]`*(buffer: LoaderBuffer, i: int): var uint8 {.inline.} = |