diff options
author | bptato <nincsnevem662@gmail.com> | 2023-05-11 18:13:38 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-05-11 18:13:38 +0200 |
commit | 34b90a0b40fbb624655a2ff8624e89101d71299b (patch) | |
tree | 372a790b769ce968afd2035b96de1679a65116e6 /src/io/request.nim | |
parent | 87f9bd656b2a8a8d4ebd029ba6a78f1dc93558eb (diff) | |
download | chawan-34b90a0b40fbb624655a2ff8624e89101d71299b.tar.gz |
Fix some fetch crashes
Now it should work for very basic use-cases
Diffstat (limited to 'src/io/request.nim')
-rw-r--r-- | src/io/request.nim | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/io/request.nim b/src/io/request.nim index ce42c61b..3cb277a9 100644 --- a/src/io/request.nim +++ b/src/io/request.nim @@ -211,13 +211,19 @@ func getOrDefault*(headers: HeaderList, k: string, default = ""): string = else: default -proc text*(response: Response): string {.jsfunc.} = - #TODO: this looks pretty unsafe. - result = response.body.readAll() - response.body.close() +#TODO: this should be a property of body +proc close*(response: Response) {.jsfunc.} = response.bodyUsed = true if response.unregisterFun != nil: response.unregisterFun() + if response.body != nil: + response.body.close() + +proc text*(response: Response): string {.jsfunc.} = + if response.body == nil: + return "" + result = response.body.readAll() + response.close() #TODO: get rid of this proc readAll*(response: Response): string {.jsfunc.} = @@ -231,14 +237,6 @@ proc Response_json*(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue var s = response.text() return JS_ParseJSON(ctx, addr s[0], cast[csize_t](s.len), cstring"<input>") -#TODO: this should be a property of body -proc close*(response: Response) {.jsfunc.} = - #TODO: this looks pretty unsafe - response.body.close() - response.bodyUsed = true - if response.unregisterFun != nil: - response.unregisterFun() - func credentialsMode*(attribute: CORSAttribute): CredentialsMode = case attribute of NO_CORS, ANONYMOUS: |