about summary refs log tree commit diff stats
path: root/src/loader
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-12 20:35:30 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-12 20:36:39 +0100
commita2eadfb39099b2e8bfd543f00d75b64916931959 (patch)
tree3df7afbb5a75ee51c1503b7961e940a3f37962a2 /src/loader
parent8e6783a45fba48dd8f63fe7486e4691f05220b52 (diff)
downloadchawan-a2eadfb39099b2e8bfd543f00d75b64916931959.tar.gz
Add pager.externFilterSource
useful for filtering stuff through commands like rdrview
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/loader.nim18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 0755d427..6183e771 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -233,7 +233,7 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) =
     handle.rejectHandle(ERROR_TOO_MANY_REWRITES)
 
 proc loadFromCache(ctx: LoaderContext, stream: SocketStream, request: Request) =
-  let handle = newLoaderHandle(stream, false, request.clientId)
+  let handle = newLoaderHandle(stream, request.canredir, request.clientId)
   let surl = $request.url
   let cachedHandle = ctx.findCachedHandle(surl)
   ctx.cacheMap.withValue(surl, p):
@@ -270,6 +270,17 @@ proc loadFromCache(ctx: LoaderContext, stream: SocketStream, request: Request) =
     output.parent = cachedHandle
     cachedHandle.outputs.add(output)
     ctx.outputMap[output.ostream.fd] = output
+  if handle.outputs.len > 0:
+    let output = handle.output
+    if output.sostream != nil:
+      try:
+        handle.output.sostream.swrite(true)
+      except IOError:
+        # ignore error, that just means the buffer has already closed the
+        # stream
+        discard
+      output.sostream.close()
+      output.sostream = nil
   handle.close()
 
 proc onLoad(ctx: LoaderContext, stream: SocketStream) =
@@ -794,12 +805,9 @@ proc onError*(loader: FileLoader, fd: int) =
     buffer[].buf = ""
     response.unregisterFun()
 
-proc doRequest*(loader: FileLoader, request: Request, canredir = false):
-    Response =
+proc doRequest*(loader: FileLoader, request: Request): Response =
   let response = Response(url: request.url)
   let stream = connectSocketStream(loader.process, false, blocking = true)
-  if canredir:
-    request.canredir = true #TODO set this somewhere else?
   request.clientId = (loader.clientPid, int(stream.fd))
   stream.swrite(LOAD)
   stream.swrite(request)