about summary refs log tree commit diff stats
path: root/src/server
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-25 04:01:20 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-25 04:01:20 +0100
commit929b85d06cfa97cf7b211b447fdd157384e028e3 (patch)
treed1f45cc6ed735e1015602b92e65b752ad908b99b /src/server
parent6e98894199442e2213dc89e0c5fe970029f05b65 (diff)
downloadchawan-929b85d06cfa97cf7b211b447fdd157384e028e3.tar.gz
buffer: fix rewind with mailcap entries
Cache mailcap entry output too, then delete it when the buffer can no
longer read from it.

(Maybe it would be useful to instead preserve it and allow viewSource
for HTML output too? Hmm.)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/buffer.nim16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 783da17b..7e002a31 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -115,6 +115,7 @@ type
     validateBuf: seq[char]
     charsetStack: seq[Charset]
     charset: Charset
+    tmpCacheFlag: bool
 
   InterfaceOpaque = ref object
     stream: Stream
@@ -629,7 +630,7 @@ proc processData0(buffer: Buffer, data: openArray[char]): bool =
   else:
     var plaintext = buffer.document.findFirst(TAG_PLAINTEXT)
     if plaintext == nil:
-      const s = "<plaintext id='text'>"
+      const s = "<plaintext>"
       doAssert buffer.htmlParser.parseBuffer(s) != PRES_STOP
       plaintext = buffer.document.findFirst(TAG_PLAINTEXT)
     if data.len > 0:
@@ -640,6 +641,7 @@ proc processData0(buffer: Buffer, data: openArray[char]): bool =
         Text(lastChild).data &= text
       else:
         plaintext.insert(buffer.document.createTextNode(text), nil)
+      plaintext.invalid = true
   true
 
 func canSwitch(buffer: Buffer): bool {.inline.} =
@@ -801,7 +803,7 @@ type ConnectResult* = object
   charset*: Charset
 
 proc rewind(buffer: Buffer): bool =
-  let request = newRequest(buffer.url, fromcache = true)
+  let request = newRequest(buffer.request.url, fromcache = true)
   let response = buffer.loader.doRequest(request)
   if response.body == nil:
     return false
@@ -933,12 +935,15 @@ proc redirectToFd*(buffer: Buffer, fd: FileHandle, wait, cache: bool)
   buffer.istream.close()
 
 proc readFromFd*(buffer: Buffer, url: URL, ishtml: bool) {.proxy.} =
-  let request = newRequest(url)
+  let request = newRequest(url, canredir = true)
   buffer.request = request
   buffer.setHTML(ishtml)
   let response = buffer.loader.doRequest(request)
   buffer.istream = response.body
+  buffer.istream.swrite(false) # no redir
+  buffer.istream.swrite(true) # cache on
   buffer.istream.setBlocking(false)
+  buffer.tmpCacheFlag = true
   buffer.fd = response.body.fd
   buffer.selector.registerHandle(buffer.fd, {Read}, 0)
 
@@ -1131,6 +1136,8 @@ proc finishLoad(buffer: Buffer): EmptyPromise =
   buffer.loader.unregistered.add(buffer.fd)
   buffer.fd = -1
   buffer.istream.close()
+  if buffer.tmpCacheFlag:
+    buffer.loader.removeCachedURL($buffer.request.url)
   return buffer.loadResources()
 
 type LoadResult* = tuple[
@@ -1192,8 +1199,7 @@ proc onload(buffer: Buffer) =
           buffer.do_reshape()
           res.lines = buffer.lines.len
           buffer.state = bsLoaded
-          if buffer.document != nil: # may be nil if not buffer.ishtml
-            buffer.document.readyState = rsComplete
+          buffer.document.readyState = rsComplete
           buffer.dispatchLoadEvent()
           buffer.resolveTask(LOAD, res)
         )