about summary refs log tree commit diff stats
path: root/src/io/buffer.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-08-18 17:09:52 +0200
committerbptato <nincsnevem662@gmail.com>2022-08-18 17:09:52 +0200
commita78c26198e747d4de887e1f582d29f14fb59391b (patch)
treedbea97fe93618e146dd0e3901d54328e86d54fd1 /src/io/buffer.nim
parente2203257e07aada157be9d0a948273cb9d683072 (diff)
downloadchawan-a78c26198e747d4de887e1f582d29f14fb59391b.tar.gz
Use a separate process for file loading
Not very useful for now, since we still have to load the entire page
before parsing it.
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r--src/io/buffer.nim24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 08feb73f..e6c290c7 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -14,6 +14,8 @@ import html/htmlparser
 import io/cell
 import io/lineedit
 import io/loader
+import io/request
+import io/serialize
 import io/term
 import js/regex
 import layout/box
@@ -841,10 +843,17 @@ proc loadResources(buffer: Buffer, document: Document) =
       if elem.rel == "stylesheet":
         let url = parseUrl(elem.href, document.location.some)
         if url.issome:
-          if url.get.scheme == buffer.location.scheme:
-            let res = buffer.loader.getPage(url.get)
-            if res.s != nil and res.contenttype == "text/css":
-              let sheet = parseStylesheet(res.s)
+          let url = url.get
+          if url.scheme == buffer.location.scheme:
+            let fs = buffer.loader.getPage(newRequest(url))
+            if fs.s != nil and fs.contenttype == "text/css":
+              var res = newStringStream()
+              while true:
+                var s: string
+                buffer.istream.sread(s)
+                if s == "": break
+                res.write(s)
+              let sheet = parseStylesheet(res)
               elem.sheet = sheet
 
     for child in elem.children_rev:
@@ -854,8 +863,11 @@ proc load*(buffer: Buffer) =
   case buffer.contenttype
   of "text/html":
     if not buffer.streamclosed:
-      buffer.source = buffer.istream.readAll()
-      buffer.istream.close()
+      while true:
+        var s: string
+        buffer.istream.sread(s)
+        if s == "": break
+        buffer.source &= s
       buffer.istream = newStringStream(buffer.source)
       buffer.document = parseHTML5(buffer.istream)
       buffer.streamclosed = true