Add global state initialization functions

This commit is contained in:
2025-07-21 21:37:02 +02:00
parent a2912b5191
commit 58f8ace725
17 changed files with 242 additions and 94 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ int main(void)
// Perform the request. This will block the thread
// until an error occurs or the request completes.
HTTP_Response *res = http_get(
HTTP_STR("http://example.com/index.html"),
HTTP_STR("http://coz.is/index.html"),
headers, HTTP_COUNT(headers)
);
@@ -45,7 +45,7 @@ int main(void)
// When we are done reading from the response object
// we must free the request's resources.
http_request_free(res);
http_response_free(res);
// All done. Deinitialize the library.
http_global_free();
+4 -4
View File
@@ -3,7 +3,8 @@
#include <string.h>
#include <chttp.h>
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
if (argc < 2) {
printf("Usage: %s <url1> [url2 ...]\n", argv[0]);
return 1;
@@ -13,13 +14,12 @@ int main(int argc, char **argv) {
HTTP_Client *client = http_client_init();
for (int i = 1; i < argc; i++) {
int k = i-1;
HTTP_RequestBuilder builder;
if (http_client_get_builder(client, &builder) < 0) {
printf("request creation error\n");
return -1;
}
http_request_builer_line(builder, HTTP_METHOD_GET, (HTTP_String) { argv[i], strlen(argv[i]) });
http_request_builder_line(builder, HTTP_METHOD_GET, (HTTP_String) { argv[i], strlen(argv[i]) });
http_request_builder_submit(builder);
printf("request submitted\n");
}
@@ -35,7 +35,7 @@ int main(int argc, char **argv) {
printf("Status: %d\n", res->status);
printf("Body: %.*s\n", HTTP_UNPACK(res->body));
http_request_free(res);
http_response_free(res);
}
http_client_free(client);