about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-05-20 17:55:12 +0200
committerbptato <nincsnevem662@gmail.com>2023-05-20 18:05:33 +0200
commit7c612d65be345fd1ef156f95bb033d9bbf8aece8 (patch)
tree826d4dd9d63e2cb45beb04146ef8552807d2f62b /src/io
parent506f095d3fac57c8715f375118efe4ceccb6228c (diff)
downloadchawan-7c612d65be345fd1ef156f95bb033d9bbf8aece8.tar.gz
Add url getter to request
Diffstat (limited to 'src/io')
-rw-r--r--src/io/request.nim11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/io/request.nim b/src/io/request.nim
index 3cb277a9..f6fe5a73 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -79,6 +79,13 @@ type
   MimeData* = object
     content*: seq[MimePart]
 
+proc Request_url(ctx: JSContext, this: JSValue, magic: cint): JSValue {.cdecl.} =
+  let op = getOpaque0(this)
+  if unlikely(not ctx.isInstanceOf(this, "Request") or op == nil):
+    return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Request")
+  let request = cast[Request](op)
+  return toJS(ctx, $request.url)
+
 iterator pairs*(headers: HeaderList): (string, string) =
   for k, vs in headers.table:
     for v in vs:
@@ -229,7 +236,7 @@ proc text*(response: Response): string {.jsfunc.} =
 proc readAll*(response: Response): string {.jsfunc.} =
   return response.text()
 
-proc Response_json*(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue): JSValue {.cdecl.} =
+proc Response_json(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue): JSValue {.cdecl.} =
   let op = getOpaque0(this)
   if unlikely(not ctx.isInstanceOf(this, "Response") or op == nil):
     return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Response")
@@ -245,6 +252,6 @@ func credentialsMode*(attribute: CORSAttribute): CredentialsMode =
     return INCLUDE
 
 proc addRequestModule*(ctx: JSContext) =
-  ctx.registerType(Request)
+  ctx.registerType(Request, extra_getset = [TabGetSet(name: "url", get: Request_url)])
   ctx.registerType(Response, extra_funcs = [TabFunc(name: "json", fun: Response_json)])
   ctx.registerType(HeaderList)