Files
cHTTP/examples/simple_client.c
T
Claude 737d81f270 Fix compilation errors in cookie_jar branch
This commit fixes multiple compilation errors introduced by the refactoring:

1. Added missing http_client_conn_free() helper function
2. Fixed cookie_jar reference (cookie_jar->count to client->cookie_jar.count)
3. Restored missing HTTP_ClientConn fields: handle, client, and url
4. Fixed undefined 'conn' variable in http_client_get_builder (changed to 'i')
5. Fixed incorrect field reference (entry.domain.len to domain.len)
6. Added missing closing parenthesis in should_send_cookie
7. Removed duplicate 'path' variable declaration
8. Fixed cookie jar access to use builder.client instead of conn->client
9. Fixed byte_queue_write calls to use .ptr and .len instead of HTTP_String structs
10. Fixed missing -> operators in url_to_connect_target
11. Fixed undefined 'url' variable by using conn->url
12. Fixed headers[i].value to set_cookie.value in save_one_cookie
13. Fixed typo: antry to entry
14. Fixed save_one_cookie parameter type (headers[i] instead of headers[i].value)
15. Fixed print_bytes calls to create HTTP_String structs
16. Added logic to store socket handle when connection is established
17. Updated http_client_get_builder signature to return HTTP_RequestBuilder
18. Updated simple_client.c example to match new API
2025-11-23 21:18:09 +00:00

60 lines
1.3 KiB
C

#include "../chttp.h"
#ifdef _WIN32
#define POLL WSAPoll
#else
#define POLL poll
#endif
int main(void)
{
HTTP_Client client;
if (http_client_init(&client) < 0)
return -1;
HTTP_RequestBuilder builder = http_client_get_builder(&client);
http_request_builder_url(builder,
HTTP_METHOD_GET,
HTTP_STR("http://coz.is")
);
http_request_builder_header(builder,
HTTP_STR("Greeting: Hello from the cHTTP example!"));
if (http_request_builder_send(builder) < 0)
return -1;
for (;;) {
void *ptrs[HTTP_CLIENT_CAPACITY+1];
struct pollfd polled[HTTP_CLIENT_CAPACITY+1];
EventRegister reg = {
.ptrs=ptrs,
.polled=polled,
.num_polled=0,
.max_polled=HTTP_CLIENT_CAPACITY+1,
};
if (http_client_register_events(&client, &reg) < 0)
return -1;
if (reg.num_polled > 0)
POLL(reg.polled, reg.num_polled, -1);
if (http_client_process_events(&client, &reg) < 0)
return -1;
HTTP_Response *response;
void *user;
while (http_client_next_response(&client, &response, &user)) {
// TODO
http_free_response(response);
}
}
http_client_free(&client);
return 0;
}