about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/io')
-rw-r--r--src/io/loader.nim24
-rw-r--r--src/io/process.nim16
-rw-r--r--src/io/request.nim6
3 files changed, 24 insertions, 22 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.
diff --git a/src/io/process.nim b/src/io/process.nim
new file mode 100644
index 00000000..e081ecc6
--- /dev/null
+++ b/src/io/process.nim
@@ -0,0 +1,16 @@
+when defined(posix):
+  import posix
+
+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
+
diff --git a/src/io/request.nim b/src/io/request.nim
index 5e62dbc4..86bfe834 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -18,12 +18,6 @@ type
     body*: Option[string]
     multipart*: Option[MimeData]
 
-  FileLoader* = ref object
-    defaultHeaders*: HeaderList
-    process*: int
-    istream*: Stream
-    ostream*: Stream
-
   LoadResult* = object
     s*: Stream
     res*: int