aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-02-04 15:32:01 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-02-04 15:32:01 -0500
commit3b00aef3e4865678d26f6a14d994518042591857 (patch)
treed44a4f120b3f9b4724cee216ecda0a53b817293d /examples
parent812b1e4746d2a0fc217f31ec90114d041ab21e6f (diff)
Use `defer` in http module
Diffstat (limited to 'examples')
-rw-r--r--examples/http/http.tm10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/http/http.tm b/examples/http/http.tm
index e7221b2c..2555986f 100644
--- a/examples/http/http.tm
+++ b/examples/http/http.tm
@@ -23,6 +23,13 @@ func _send(method:_Method, url:Text, data:Text?, headers=[:Text] -> HTTPResponse
curl_easy_setopt(curl, CURLOPT_WRITEDATA, _$save_chunk.userdata);
}
+ defer:
+ inline C {
+ if (chunk)
+ curl_slist_free_all(chunk);
+ curl_easy_cleanup(curl);
+ }
+
when method is POST:
inline C {
curl_easy_setopt(curl, CURLOPT_POST, 1L);
@@ -71,9 +78,6 @@ func _send(method:_Method, url:Text, data:Text?, headers=[:Text] -> HTTPResponse
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &_$code);
- if (chunk)
- curl_slist_free_all(chunk);
- curl_easy_cleanup(curl);
}
return HTTPResponse(Int(code), "":join(chunks))