about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-05-21 22:26:15 +0200
committerbptato <nincsnevem662@gmail.com>2022-05-21 22:26:15 +0200
commit3aea225b34766ce574ad4c8ed7570861f960e34d (patch)
treefdb443e77a4673cca8be4228dd2efd8e6562a04e
parent087f89ecb41f5a495d83ab82fc7f38e704a516a6 (diff)
downloadchawan-3aea225b34766ce574ad4c8ed7570861f960e34d.tar.gz
Update loader.nim
-rw-r--r--src/io/loader.nim12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim
index 235466e9..590ba697 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -9,7 +9,7 @@ import utils/twtstr
 type
   FileLoader* = ref object
     http: HttpClient
-    headers: HttpHeaders
+    headers*: HttpHeaders
 
   LoadResult* = object
     s*: Stream
@@ -26,6 +26,7 @@ const DefaultHeaders = {
 proc newFileLoader*(headers: HttpHeaders): FileLoader =
   new(result)
   result.http = newHttpClient()
+  result.headers = headers
 
 proc newFileLoader*(): FileLoader =
   var headers = newHttpHeaders(true)
@@ -33,8 +34,7 @@ proc newFileLoader*(): FileLoader =
     headers[header[0]] = header[1]
   newFileLoader(headers)
 
-proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet,
-              mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult =
+proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult =
   if url.scheme == "file":
     when defined(windows) or defined(OS2) or defined(DOS):
       let path = url.path.serialize_unicode_dos()
@@ -55,3 +55,9 @@ proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet,
       result.contenttype = guessContentType(url.path.serialize())
     resp.bodystream.setPosition(0)
     result.s = resp.bodyStream
+
+proc getPage*(loader: FileLoader, url: string, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult =
+  let url = parseUrl(url)
+  if url.isnone:
+    raise newException(Exception, "Invalid URL")
+  loader.getPage(url.get, smethod, mimetype, body, multipart)