about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-02-09 15:56:29 +0100
committerbptato <nincsnevem662@gmail.com>2022-02-09 15:57:45 +0100
commit2edbb7b07d1b82e18e1dbe5eb58a3fcce659f783 (patch)
treed75e4c249ed6c9491c59165fd06555f68c5b428e /src/io
parentacfa008840bbd9fcdafcee4197a3a776db2d348d (diff)
downloadchawan-2edbb7b07d1b82e18e1dbe5eb58a3fcce659f783.tar.gz
Some loader polishing
Diffstat (limited to 'src/io')
-rw-r--r--src/io/buffer.nim12
-rw-r--r--src/io/loader.nim6
2 files changed, 8 insertions, 10 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 7356b084..8592b98f 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -736,7 +736,7 @@ proc loadResources(buffer: Buffer, document: Document) =
           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.readAll())
+              let sheet = parseStylesheet(res.s)
               elem.parentElement.sheets.add(sheet)
 
     for i in countdown(elem.children.high, 0):
@@ -747,14 +747,10 @@ proc load*(buffer: Buffer) =
   case buffer.contenttype
   of "text/html":
     if not buffer.streamclosed:
-      #TODO not sure what to do with this.
-      #Ideally we could just throw away the source data after parsing but then
-      #source view won't work. Well we could still generate it... best would be a
-      #config option like a) store source b) generate source
-      buffer.source = buffer.istream.readAll()
-      buffer.istream.close()
+      buffer.document = parseHtml(buffer.istream, buffer.source)
       buffer.streamclosed = true
-    buffer.document = parseHtml(newStringStream(buffer.source))
+    else:
+      buffer.document = parseHtml(newStringStream(buffer.source))
     buffer.document.location = buffer.location
     buffer.loadResources(buffer.document)
   else:
diff --git a/src/io/loader.nim b/src/io/loader.nim
index 4a10d336..d0181262 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -16,7 +16,7 @@ type
 
 const DefaultHeaders = {
   "User-Agent": "chawan",
-  "Accept": "text/html", "text/*;q=0.5",
+  "Accept": "text/html,text/*;q=0.5",
   "Accept-Language": "en;q=1.0",
   "Pragma": "no-cache",
   "Cache-control": "no-cache",
@@ -35,7 +35,9 @@ proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimet
     result.contenttype = guessContentType(path)
     result.s = newFileStream(path, fmRead)
   elif url.scheme == "http" or url.scheme == "https":
-    var requestheaders = newHttpHeaders(DefaultHeaders, true)
+    var requestheaders = newHttpHeaders(true)
+    for header in DefaultHeaders:
+      requestheaders[header[0]] = header[1]
     if mimetype != "":
       requestheaders["Content-Type"] = mimetype 
     let resp = loader.http.request(url.serialize(true), smethod, body, requestheaders, multipart)