about summary refs log tree commit diff stats
path: root/src/io/loader.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-08-20 22:18:55 +0200
committerbptato <nincsnevem662@gmail.com>2022-08-20 22:18:55 +0200
commitb8f20acb81501102032f10bb43e13682ebe68508 (patch)
tree76c0942e5a18bf257e84b583adafddb1daf523af /src/io/loader.nim
parent2d65840eb25675c046a6df144fd1d0d29a5a2514 (diff)
downloadchawan-b8f20acb81501102032f10bb43e13682ebe68508.tar.gz
Small refactoring
Diffstat (limited to 'src/io/loader.nim')
-rw-r--r--src/io/loader.nim24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim
index 4adf64bc..50a5c1c7 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -6,13 +6,12 @@ when defined(posix):
 
 import bindings/curl
 import io/http
+import io/process
 import io/request
 import io/serialize
 import types/mime
 import types/url
 
-export request
-
 const DefaultHeaders = {
   "User-Agent": "chawan",
   "Accept": "text/html,text/*;q=0.5",
@@ -21,18 +20,11 @@ const DefaultHeaders = {
   "Cache-Control": "no-cache",
 }.toTable().newHeaderList()
 
-proc doFork(): Pid =
-  result = fork()
-  if result == -1:
-    eprint "Failed to fork child process."
-    quit(1)
-  elif result != 0:
-    return result
-  discard setsid()
-  let pid = fork()
-  if pid != 0:
-    quit(0)
-  return 0
+type FileLoader* = ref object
+  defaultHeaders*: HeaderList
+  process*: int
+  istream*: Stream
+  ostream*: Stream
 
 proc loadFile(url: Url, ostream: Stream) =
   when defined(windows) or defined(OS2) or defined(DOS):
@@ -79,9 +71,9 @@ proc runFileLoader(loader: FileLoader) =
   while true:
     try:
       let request = istream.readRequest()
-      for k, v in loader.defaultHeaders:
+      for k, v in loader.defaultHeaders.table:
         if k notin request.headers.table:
-          request.headers[k] = v
+          request.headers.table[k] = v
       loader.loadResource(request, ostream)
     except IOError:
       # End-of-file, quit.