diff options
author | bptato <nincsnevem662@gmail.com> | 2023-05-20 17:55:12 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-05-20 18:05:33 +0200 |
commit | 7c612d65be345fd1ef156f95bb033d9bbf8aece8 (patch) | |
tree | 826d4dd9d63e2cb45beb04146ef8552807d2f62b /src | |
parent | 506f095d3fac57c8715f375118efe4ceccb6228c (diff) | |
download | chawan-7c612d65be345fd1ef156f95bb033d9bbf8aece8.tar.gz |
Add url getter to request
Diffstat (limited to 'src')
-rw-r--r-- | src/io/request.nim | 11 |
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) |