27#define KL_CLIENT_HOSTNAME_MAX 256
29#define KL_CLIENT_REQ_BUF_SIZE 4096
31#define KL_CLIENT_MAX_REQ_HEADERS 64
33#define KL_CLIENT_DEFAULT_TIMEOUT_MS 30000
35#define KL_CLIENT_DEFAULT_MAX_RESP (4 * 1024 * 1024)
37#define KL_CLIENT_RECV_BUF_SIZE 8192
39#define KL_CLIENT_CHUNK_BUF_SIZE 4096
41#define KL_CLIENT_CHUNK_HDR_SIZE 16
43#define KL_CLIENT_FINAL_CHUNK_LEN 5
98 int num_headers,
void *user_data);
121 void (*on_complete)(
void *user_data);
148 const char *method,
const char *url,
150 const char *body,
size_t body_len,
172 const char *method,
const char *url,
174 const char *body,
size_t body_len,
220 const char *method,
const char *url,
222 const char *body,
size_t body_len,
247 const char *method,
const char *url,
249 const char *body,
size_t body_len,
304 void (*on_complete)(
void *),
305 void *stream_user_data);
void kl_client_response_free(KlClientResponse *resp)
Free response resources (body, headers).
void kl_client_free(KlClient *client)
Free all client resources (response, buffers, parser).
KlError kl_client_last_error(const KlClient *client)
Get the specific error code from a completed async request.
ssize_t(* KlClientReadFn)(char *buf, size_t buf_len, void *user_data)
Request body streaming callback (pull-based, like read()).
Definition client.h:107
void(* KlClientDoneFn)(KlClient *client, void *user_data)
Callback invoked when an async HTTP request completes.
Definition client.h:193
KlClient * kl_client_start(KlEventCtx *ev_ctx, KlAllocator *alloc, const KlClientConfig *cfg, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, KlClientDoneFn on_done, void *user_data)
Start an asynchronous HTTP request.
int kl_client_request(KlAllocator *alloc, const KlClientConfig *cfg, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, KlClientResponse *resp)
Perform a synchronous (blocking) HTTP request.
int kl_client_error(const KlClient *client)
Check if the async request completed with an error.
KlResponseParser * kl_response_parser_llhttp_s(size_t max_response_size, KlAllocator *alloc, KlClientBodyFn on_body, KlClientHeadersFn on_headers, void(*on_complete)(void *), void *stream_user_data)
Create a streaming-capable llhttp response parser.
void kl_client_cancel(KlClient *client)
Cancel an in-flight async request (removes watcher, closes socket).
int kl_client_request_s(KlAllocator *alloc, const KlClientConfig *cfg, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, const KlClientStreamCfg *stream, KlClientResponse *resp)
Perform a synchronous (blocking) HTTP request with streaming.
KlClient * kl_client_start_s(KlEventCtx *ev_ctx, KlAllocator *alloc, const KlClientConfig *cfg, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, const KlClientStreamCfg *stream, KlClientDoneFn on_done, void *user_data)
Start an asynchronous HTTP request with streaming.
int(* KlClientBodyFn)(const char *data, size_t len, void *user_data)
Response body streaming callback (push-based).
Definition client.h:91
struct KlClient KlClient
Definition client.h:185
int(* KlClientHeadersFn)(int status, const KlClientHeader *headers, int num_headers, void *user_data)
Called when response headers are complete.
Definition client.h:97
const KlClientResponse * kl_client_response(const KlClient *client)
Get the response from a completed async request.
KlError
Diagnostic error codes for Keel public functions.
Definition error.h:11
Bring-your-own allocator vtable.
Definition allocator.h:12
KlTlsConfig * tls
Definition client.h:76
KlProxyConfig * proxy
Definition client.h:79
KlDecompressConfig * decompress
Definition client.h:78
size_t max_response_size
Definition client.h:75
KlResolver * resolver
Definition client.h:77
int timeout_ms
Definition client.h:74
KlClientHeader * headers
Definition client.h:67
char * body
Definition client.h:65
KlError error
Definition client.h:70
KlAllocator alloc
Definition client.h:69
int num_headers
Definition client.h:68
size_t body_len
Definition client.h:66
int status
Definition client.h:64
Per-request streaming configuration.
Definition client.h:118
KlClientBodyFn on_body
Definition client.h:119
KlClientHeadersFn on_headers
Definition client.h:120
KlClientReadFn body_read
Definition client.h:123
void * user_data
Definition client.h:125
Decompression configuration.
Definition decompress.h:79
Composable event loop context.
Definition event_ctx.h:42
HTTP proxy configuration (borrowed pointers, caller-owned).
Definition client.h:50
uint16_t port
Definition client.h:52
const char * auth
Definition client.h:53
const char * host
Definition client.h:51
Async DNS resolver vtable.
Definition resolver.h:40
TLS configuration for KlConfig.
Definition tls.h:108