about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-08 11:34:29 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-08 11:34:29 +0200
commitccacdb2b1d735b0708d006fd6c82df98ea0b96c9 (patch)
tree3a7d2a61f9e4a739df0746274fb76182759753a3
parent34af03d4f5baa24b6a8c25434bc26b92fe24a11a (diff)
downloadchawan-ccacdb2b1d735b0708d006fd6c82df98ea0b96c9.tar.gz
fetch: allow string input, allow init dictionary
-rw-r--r--src/display/client.nim7
-rw-r--r--src/html/env.nim6
2 files changed, 9 insertions, 4 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index c531e4a6..d5140de8 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -36,6 +36,7 @@ import ips/serversocket
 import ips/socketstream
 import js/base64
 import js/domexception
+import js/error
 import js/fromjs
 import js/intl
 import js/javascript
@@ -104,8 +105,10 @@ proc finalize(client: Client) {.jsfin.} =
 proc doRequest(client: Client, req: Request): Response {.jsfunc.} =
   return client.loader.doRequest(req)
 
-proc fetch(client: Client, req: Request): FetchPromise {.jsfunc.} =
-  return client.loader.fetch(req)
+proc fetch[T: Request|string](client: Client, req: T, init = none(JSValue)):
+    JSResult[FetchPromise] {.jsfunc.} =
+  let req = ?newRequest(client.jsctx, req, init)
+  return ok(client.loader.fetch(req))
 
 proc interruptHandler(rt: JSRuntime, opaque: pointer): int {.cdecl.} =
   let client = cast[Client](opaque)
diff --git a/src/html/env.nim b/src/html/env.nim
index f48407e3..687c577a 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -66,9 +66,11 @@ proc addNavigatorModule(ctx: JSContext) =
   ctx.registerType(PluginArray)
   ctx.registerType(MimeTypeArray)
 
-proc fetch(window: Window, req: Request): FetchPromise {.jsfunc.} =
+proc fetch[T: Request|string](window: Window, req: T, init = none(JSValue)):
+    JSResult[FetchPromise] {.jsfunc.} =
   if window.loader.isSome:
-    return window.loader.get.fetch(req)
+    let req = ?newRequest(window.jsctx, req, init)
+    return ok(window.loader.get.fetch(req))
 
 proc setTimeout[T: JSValue|string](window: Window, handler: T,
     timeout = 0i32): int32 {.jsfunc.} =