libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
Loading...
Searching...
No Matches
fetch.h
Go to the documentation of this file.
1
31#ifndef FETCH_H
32#define FETCH_H
33
34/* Include generated version information */
35#include "cookie.h"
36#include "version.h"
37#include <stdbool.h>
38#include <stddef.h>
39#include <stdint.h>
40#include <time.h>
41
48#if defined(_WIN32) || defined(_WIN64)
49#include <windows.h>
51typedef HANDLE FETCH_FILE_HANDLE;
53#define FETCH_INVALID_FILE_HANDLE INVALID_HANDLE_VALUE
54#else
55#include <stdio.h>
57typedef FILE *FETCH_FILE_HANDLE;
59#define FETCH_INVALID_FILE_HANDLE NULL
60#endif
61
78
116
125#define FETCH_USER_AGENT "libfetch/" FETCH_VERSION_STRING
126
137static inline const char *fetch_version(void) { return FETCH_VERSION; }
138
143static inline const char *fetch_version_string(void) {
144 return FETCH_VERSION_STRING;
145}
146
151static inline int fetch_version_major(void) { return FETCH_VERSION_MAJOR; }
152
157static inline int fetch_version_minor(void) { return FETCH_VERSION_MINOR; }
158
163static inline int fetch_version_patch(void) { return FETCH_VERSION_PATCH; }
164
172static inline int fetch_version_compare(int major, int minor, int patch) {
173 int current = FETCH_VERSION_NUMBER;
174 int compare = (major * 10000) + (minor * 100) + patch;
175 return current - compare;
176}
177
185static inline bool fetch_version_at_least(int major, int minor, int patch) {
186 return fetch_version_compare(major, minor, patch) >= 0;
187}
188
208
210#define FETCH_FLAG_GET(flags, bit) (((flags) >> (bit)) & 1U)
212#define FETCH_FLAG_SET(flags, bit) ((flags) | (1U << (bit)))
214#define FETCH_FLAG_CLEAR(flags, bit) ((flags) & ~(1U << (bit)))
216#define FETCH_FLAG_TOGGLE(flags, bit) ((flags) ^ (1U << (bit)))
217
240
258
275
295
312
329
355
377
393typedef struct fetch_headers {
394 char **keys;
395 char **values;
396 size_t count;
397 size_t capacity;
399
403typedef struct {
405 size_t index;
407
427
441typedef struct {
444 union {
445 // Memory-based body data (for TEXT, JSON, BINARY, FORM_DATA)
446 struct {
447 const void *data;
448 size_t size;
449 } memory;
450
451 // File streaming data (for FILE type)
452 struct {
454 size_t size;
455 size_t offset;
459 void *userdata;
460 } file;
461 } data;
462
463 const char *content_type;
465
499
528
542typedef void (*fetch_on_fulfilled_cb)(fetch_response_t *response,
543 void *userdata);
544
551typedef void (*fetch_on_rejected_cb)(fetch_error_t error, const char *message,
552 void *userdata);
553
577
600
608
621
665fetch_response_t *fetch(const char *url, fetch_init_t *init);
666
724fetch_promise_t *fetch_async(const char *url, fetch_init_t *init);
725
760
791bool fetch_promise_await(fetch_promise_t *promise, uint32_t timeout_ms);
792
811bool fetch_promise_cancel(fetch_promise_t *promise, const char *reason);
812
819bool fetch_promise_cancelled(const fetch_promise_t *promise);
820
839
846
853
859const char *fetch_promise_error_message(const fetch_promise_t *promise);
860
866bool fetch_promise_pending(const fetch_promise_t *promise);
867
873bool fetch_promise_fulfilled(const fetch_promise_t *promise);
874
880bool fetch_promise_rejected(const fetch_promise_t *promise);
881
913bool fetch_event_loop_start(void);
914
923void fetch_event_loop_stop(void);
924
966int fetch_event_loop_process(uint32_t timeout_ms);
967
973
1005
1012void fetch_headers_free(fetch_headers_t *headers);
1013
1028void fetch_headers_append(fetch_headers_t *headers, const char *name,
1029 const char *value);
1030
1044void fetch_headers_set(fetch_headers_t *headers, const char *name,
1045 const char *value);
1046
1052void fetch_headers_delete(fetch_headers_t *headers, const char *name);
1053
1070const char *fetch_headers_get(const fetch_headers_t *headers, const char *name);
1071
1078bool fetch_headers_has(const fetch_headers_t *headers, const char *name);
1079
1086
1105bool fetch_headers_next(fetch_headers_iterator_t *iter, const char **key,
1106 const char **value);
1107
1135fetch_body_t *fetch_body_text(const char *text);
1136
1153fetch_body_t *fetch_body_json(const char *json);
1154
1175fetch_body_t *fetch_body_binary(const void *data, size_t size,
1176 const char *content_type);
1177
1194fetch_body_t *fetch_body_form_data(const char *form_data);
1195
1217
1330fetch_body_t *fetch_body_file(FETCH_FILE_HANDLE file_handle, size_t size,
1331 const char *content_type, bool close_on_free,
1332 fetch_file_continue_cb continue_cb,
1333 void *userdata);
1334
1343void fetch_body_free(fetch_body_t *body);
1344
1361
1369
1379 const char *name, const char *value);
1380
1390 const char *name, const char *value);
1391
1398 const char *name);
1399
1409 const char *name);
1410
1418 const char *name);
1419
1442char *
1444
1452
1464 const char **key, const char **value);
1465
1494const char *fetch_response_text(fetch_response_t *response);
1495
1515const void *fetch_response_array_buffer(fetch_response_t *response,
1516 size_t *size);
1517
1526const char *fetch_response_json(fetch_response_t *response);
1527
1533bool fetch_response_ok(const fetch_response_t *response);
1534
1540uint16_t fetch_response_status(const fetch_response_t *response);
1541
1549const char *fetch_response_status_text(const fetch_response_t *response);
1550
1558const char *fetch_response_url(const fetch_response_t *response);
1559
1568
1578
1586
1625
1632 const char *reason);
1633
1640
1648
1689
1697void fetch_init_free(fetch_init_t *init);
1698
1706
1716
1726
1733fetch_init_t *fetch_init_timeout(fetch_init_t *init, uint32_t timeout_ms);
1734
1744 fetch_abort_controller_t *signal);
1745
1765const char *fetch_method_to_string(http_method_t method);
1766
1776http_method_t fetch_method_from_string(const char *method_str);
1777
1789bool fetch_is_valid_url(const char *url);
1790
1805const char *fetch_error_to_string(fetch_error_t error);
1806
1833
1840static inline bool fetch_config_get_flag(uint32_t flags, fetch_flag_bit_t bit) {
1841 return FETCH_FLAG_GET(flags, bit) != 0;
1842}
1843
1850static inline void fetch_config_set_flag(fetch_config_t *config,
1851 fetch_flag_bit_t flag, bool value) {
1852 if (!config)
1853 return;
1854
1855 if (value) {
1856 config->flags = FETCH_FLAG_SET(config->flags, flag);
1857 } else {
1858 config->flags = FETCH_FLAG_CLEAR(config->flags, flag);
1859 }
1860}
1861
1886 fetch_config_t config = {.user_agent = FETCH_USER_AGENT,
1887 .origin = NULL,
1888 .cookie_jar = NULL,
1889 .default_timeout_ms = 30000,
1890 .max_connections = 1000,
1891 .max_connections_per_host = 6,
1892 .keep_alive_timeout_ms = 115000,
1893 .pool_cleanup_interval_ms = 30000,
1894 .max_pooled_connections = 100,
1895 .flags = (1U << FETCH_FLAG_KEEP_ALIVE_DEFAULT) |
1899 return config;
1900}
1901
1921void fetch_global_init(const fetch_config_t *config);
1922
1933void fetch_global_dispose(void);
1934
1951
1963size_t fetch_cookie_jar_count(const char *domain_filter);
1964
1968void fetch_cookie_jar_clear(void);
1969
1975void fetch_disable_cookies(void);
1976
2004cookie_jar_t *fetch_create_cookie_jar(const char *persistent_file);
2005
2013
2020bool fetch_save_cookies(const char *filename, cookie_jar_t *jar);
2021
2028bool fetch_load_cookies(const char *filename, cookie_jar_t *jar);
2029
2035void fetch_cookie_jar_print(cookie_jar_t *jar, const char *domain_filter);
2036
2054void fetch_promise_free(fetch_promise_t *promise);
2055
2065#define FETCH_GET(url) fetch(url, NULL)
2066
2068#define FETCH_ASYNC_GET(url) fetch_async(url, NULL)
2069
2071#define FETCH_IS_OK(response) \
2072 ((response) != NULL && fetch_response_ok(response))
2073
2075#define FETCH_PROMISE_IS_DONE(promise) \
2076 ((promise) != NULL && fetch_promise_poll(promise))
2077
2086#define FETCH_TIMEOUT_INFINITE 0
2087#define FETCH_TIMEOUT_DEFAULT 30000
2088#define FETCH_TIMEOUT_SHORT 5000
2089#define FETCH_TIMEOUT_LONG 60000
2688#endif /* FETCH_H */
HTTP Cookie management library for C.
#define FETCH_USER_AGENT
Default user agent string.
Definition fetch.h:125
void fetch_abort_controller_free(fetch_abort_controller_t *controller)
Free an abort controller.
Definition fetch.c:8857
fetch_abort_controller_t * fetch_abort_controller_new(void)
Create a new abort controller.
Definition fetch.c:8833
bool fetch_abort_controller_aborted(const fetch_abort_controller_t *controller)
Check if controller has been aborted.
Definition fetch.c:8852
void fetch_abort_controller_abort(fetch_abort_controller_t *controller, const char *reason)
Abort operations using this controller.
Definition fetch.c:8839
struct fetch_abort_controller fetch_abort_controller_t
Abort controller for cancelling requests.
fetch_body_t * fetch_body_text(const char *text)
Create a text body.
Definition fetch.c:8207
fetch_body_t * fetch_body_form_data(const char *form_data)
Create a form data body.
Definition fetch.c:8274
void fetch_body_free(fetch_body_t *body)
Free a body object.
Definition fetch.c:8295
fetch_body_t * fetch_body_json(const char *json)
Create a JSON body.
Definition fetch.c:8228
fetch_body_t * fetch_body_file(FETCH_FILE_HANDLE file_handle, size_t size, const char *content_type, bool close_on_free, fetch_file_continue_cb continue_cb, void *userdata)
Create a body from a file handle for streaming.
Definition fetch.c:8788
fetch_body_t * fetch_body_binary(const void *data, size_t size, const char *content_type)
Create a binary body.
Definition fetch.c:8249
fetch_body_t * fetch_body_url_search_params(fetch_url_search_params_t *params)
Create a body from URL search parameters.
Definition fetch.c:8766
fetch_body_type_t
Types of request/response bodies.
Definition fetch.h:419
@ FETCH_BODY_BINARY
Definition fetch.h:422
@ FETCH_BODY_JSON
Definition fetch.h:424
@ FETCH_BODY_TEXT
Definition fetch.h:421
@ FETCH_BODY_NONE
Definition fetch.h:420
@ FETCH_BODY_FORM_DATA
Definition fetch.h:423
@ FETCH_BODY_FILE
Definition fetch.h:425
fetch_cache_t
Cache control modes.
Definition fetch.h:287
@ FETCH_CACHE_NO_STORE
Definition fetch.h:289
@ FETCH_CACHE_NO_CACHE
Definition fetch.h:291
@ FETCH_CACHE_RELOAD
Definition fetch.h:290
@ FETCH_CACHE_FORCE_CACHE
Definition fetch.h:292
@ FETCH_CACHE_ONLY_IF_CACHED
Definition fetch.h:293
@ FETCH_CACHE_DEFAULT
Definition fetch.h:288
void fetch_global_dispose(void)
Clean up the fetch library.
Definition fetch.c:7620
void fetch_global_init(const fetch_config_t *config)
Initialize the fetch library with configuration.
Definition fetch.c:7519
static fetch_config_t fetch_config_default(void)
Get default configuration.
Definition fetch.h:1885
struct fetch_config fetch_config_t
Global configuration for the fetch library.
static bool fetch_config_get_flag(uint32_t flags, fetch_flag_bit_t bit)
Get a configuration flag value.
Definition fetch.h:1840
static void fetch_config_set_flag(fetch_config_t *config, fetch_flag_bit_t flag, bool value)
Set or clear a configuration flag.
Definition fetch.h:1850
fetch_response_t * fetch(const char *url, fetch_init_t *init)
Make a synchronous HTTP request (BLOCKING)
Definition fetch.c:7835
fetch_promise_t * fetch_async(const char *url, fetch_init_t *init)
Make an asynchronous HTTP request (NON-BLOCKING)
Definition fetch.c:7764
fetch_credentials_t
Credential handling modes.
Definition fetch.h:270
@ FETCH_CREDENTIALS_SAME_ORIGIN
Definition fetch.h:272
@ FETCH_CREDENTIALS_OMIT
Definition fetch.h:271
@ FETCH_CREDENTIALS_INCLUDE
Definition fetch.h:273
fetch_error_t
Error codes for fetch operations.
Definition fetch.h:341
@ FETCH_ERROR_INVALID_METHOD
Definition fetch.h:346
@ FETCH_ERROR_MEMORY
Definition fetch.h:348
@ FETCH_ERROR_NETWORK
Definition fetch.h:343
@ FETCH_ERROR_TOO_MANY_REDIRECTS
Definition fetch.h:350
@ FETCH_ERROR_INVALID_URL
Definition fetch.h:345
@ FETCH_ERROR_CONNECTION_REFUSED
Definition fetch.h:351
@ FETCH_ERROR_ABORTED
Definition fetch.h:349
@ FETCH_ERROR_INVALID_HEADERS
Definition fetch.h:347
@ FETCH_ERROR_TIMEOUT
Definition fetch.h:344
@ FETCH_ERROR_NONE
Definition fetch.h:342
@ FETCH_ERROR_PROTOCOL_ERROR
Definition fetch.h:353
@ FETCH_ERROR_DNS_RESOLUTION
Definition fetch.h:352
int fetch_event_loop_process(uint32_t timeout_ms)
Process events in the event loop (NON-BLOCKING with timeout)
Definition fetch.c:7339
void fetch_event_loop_stop(void)
Stop the event loop.
Definition fetch.c:7436
bool fetch_event_loop_is_running(void)
Check if the event loop is running.
Definition fetch.c:7472
bool fetch_event_loop_start(void)
Start the event loop.
Definition fetch.c:7407
#define FETCH_FLAG_SET(flags, bit)
Set a flag in a flags bitfield.
Definition fetch.h:212
fetch_flag_bit_t
Configuration flags for the fetch library.
Definition fetch.h:200
#define FETCH_FLAG_CLEAR(flags, bit)
Clear a flag in a flags bitfield.
Definition fetch.h:214
#define FETCH_FLAG_GET(flags, bit)
Get a flag value from a flags bitfield.
Definition fetch.h:210
@ FETCH_FLAG_DEBUG_LOGGING
Definition fetch.h:206
@ FETCH_FLAG_FOLLOW_REDIRECTS
Definition fetch.h:203
@ FETCH_FLAG_ENABLE_COMPRESSION
Definition fetch.h:204
@ FETCH_FLAG_ACCEPT_INVALID_CERTS
Definition fetch.h:202
@ FETCH_FLAG_ENABLE_COOKIES
Definition fetch.h:205
@ FETCH_FLAG_KEEP_ALIVE_DEFAULT
Definition fetch.h:201
fetch_mode_t
Request modes for CORS handling.
Definition fetch.h:252
@ FETCH_MODE_NAVIGATE
Definition fetch.h:256
@ FETCH_MODE_SAME_ORIGIN
Definition fetch.h:255
@ FETCH_MODE_NO_CORS
Definition fetch.h:254
@ FETCH_MODE_CORS
Definition fetch.h:253
FILE * FETCH_FILE_HANDLE
File handle type for streaming file content.
Definition fetch.h:57
fetch_stream_result_t(* fetch_file_continue_cb)(void *userdata)
Callback function for controlling file streaming continuation.
Definition fetch.h:115
fetch_stream_result_t
Return codes for file streaming continue callback.
Definition fetch.h:73
@ FETCH_STREAM_DONE
Definition fetch.h:75
@ FETCH_STREAM_SKIP
Definition fetch.h:76
@ FETCH_STREAM_READ
Definition fetch.h:74
fetch_headers_iterator_t fetch_headers_entries(const fetch_headers_t *headers)
Create an iterator for headers.
Definition fetch.c:8187
fetch_headers_t * fetch_headers_new(void)
Create a new headers container.
Definition fetch.c:8028
void fetch_headers_append(fetch_headers_t *headers, const char *name, const char *value)
Add a header (allows duplicates)
Definition fetch.c:8108
void fetch_headers_free(fetch_headers_t *headers)
Free a headers container and all its contents.
Definition fetch.c:8061
const char * fetch_headers_get(const fetch_headers_t *headers, const char *name)
Get the first header value with the given name.
Definition fetch.c:8169
bool fetch_headers_has(const fetch_headers_t *headers, const char *name)
Check if a header exists.
Definition fetch.c:8183
void fetch_headers_set(fetch_headers_t *headers, const char *name, const char *value)
Set a header (replaces existing)
Definition fetch.c:8131
void fetch_headers_delete(fetch_headers_t *headers, const char *name)
Remove all headers with the given name.
Definition fetch.c:8147
bool fetch_headers_next(fetch_headers_iterator_t *iter, const char **key, const char **value)
Get the next header from an iterator.
Definition fetch.c:8192
struct fetch_headers fetch_headers_t
HTTP headers container.
http_method_t
HTTP request methods.
Definition fetch.h:229
@ HTTP_METHOD_POST
Definition fetch.h:232
@ HTTP_METHOD_HEAD
Definition fetch.h:231
@ HTTP_METHOD_CONNECT
Definition fetch.h:235
@ HTTP_METHOD_DELETE
Definition fetch.h:234
@ HTTP_METHOD_GET
Definition fetch.h:230
@ HTTP_METHOD_TRACE
Definition fetch.h:237
@ HTTP_METHOD_PATCH
Definition fetch.h:238
@ HTTP_METHOD_OPTIONS
Definition fetch.h:236
@ HTTP_METHOD_PUT
Definition fetch.h:233
void fetch_init_free(fetch_init_t *init)
Free a request configuration.
Definition fetch.c:8881
fetch_init_t * fetch_init_method(fetch_init_t *init, http_method_t method)
Set HTTP method (fluent interface)
Definition fetch.c:8891
fetch_init_t * fetch_init_headers(fetch_init_t *init, fetch_headers_t *headers)
Set request headers (fluent interface)
Definition fetch.c:8897
fetch_init_t * fetch_init_timeout(fetch_init_t *init, uint32_t timeout_ms)
Set request timeout (fluent interface)
Definition fetch.c:8913
fetch_init_t * fetch_init_new(void)
Create a new request configuration.
Definition fetch.c:8861
fetch_init_t * fetch_init_body(fetch_init_t *init, fetch_body_t *body)
Set request body (fluent interface)
Definition fetch.c:8905
fetch_init_t * fetch_init_signal(fetch_init_t *init, fetch_abort_controller_t *signal)
Set abort signal (fluent interface)
Definition fetch.c:8919
void fetch_promise_free(fetch_promise_t *promise)
Free a promise object.
Definition fetch.c:8401
fetch_error_t fetch_promise_error(const fetch_promise_t *promise)
Get the error code from a rejected promise.
Definition fetch.c:8008
const char * fetch_promise_error_message(const fetch_promise_t *promise)
Get the error message from a rejected promise.
Definition fetch.c:8012
fetch_promise_state_t fetch_promise_state(const fetch_promise_t *promise)
Get the current state of a promise.
Definition fetch.c:8004
bool fetch_promise_rejected(const fetch_promise_t *promise)
Check if promise was rejected.
Definition fetch.c:8024
fetch_response_t * fetch_promise_response(const fetch_promise_t *promise)
Get the response from a fulfilled promise.
Definition fetch.c:8000
bool fetch_promise_fulfilled(const fetch_promise_t *promise)
Check if promise was fulfilled successfully.
Definition fetch.c:8020
bool fetch_promise_pending(const fetch_promise_t *promise)
Check if promise is still pending.
Definition fetch.c:8016
bool fetch_promise_poll(fetch_promise_t *promise)
Check if a promise has completed (NON-BLOCKING)
Definition fetch.c:7900
bool fetch_promise_cancel(fetch_promise_t *promise, const char *reason)
Cancel a pending promise.
Definition fetch.c:7943
bool fetch_promise_cancelled(const fetch_promise_t *promise)
Check if a promise was cancelled.
Definition fetch.c:7992
bool fetch_promise_await(fetch_promise_t *promise, uint32_t timeout_ms)
Wait for a promise to complete (BLOCKING)
Definition fetch.c:7907
fetch_promise_state_t
Promise states for asynchronous operations.
Definition fetch.h:324
@ FETCH_PROMISE_PENDING
Definition fetch.h:325
@ FETCH_PROMISE_FULFILLED
Definition fetch.h:326
@ FETCH_PROMISE_REJECTED
Definition fetch.h:327
void(* fetch_on_rejected_cb)(fetch_error_t error, const char *message, void *userdata)
Callback for promise rejection/failure.
Definition fetch.h:551
void(* fetch_on_fulfilled_cb)(fetch_response_t *response, void *userdata)
Callback for successful promise completion.
Definition fetch.h:542
struct fetch_promise fetch_promise_t
Promise for asynchronous fetch operations.
fetch_redirect_t
Redirect handling modes.
Definition fetch.h:307
@ FETCH_REDIRECT_FOLLOW
Definition fetch.h:308
@ FETCH_REDIRECT_ERROR
Definition fetch.h:309
@ FETCH_REDIRECT_MANUAL
Definition fetch.h:310
struct fetch_init fetch_init_t
Request configuration options.
void fetch_response_free(fetch_response_t *response)
Free a response object.
Definition fetch.c:8389
fetch_headers_t * fetch_response_headers(const fetch_response_t *response)
Get response headers.
Definition fetch.c:8385
fetch_response_t * fetch_response_clone(const fetch_response_t *response)
Clone a response object.
bool fetch_response_ok(const fetch_response_t *response)
Check if response is successful (2xx status)
Definition fetch.c:8369
const void * fetch_response_array_buffer(fetch_response_t *response, size_t *size)
Get response body as binary data.
Definition fetch.c:8341
const char * fetch_response_json(fetch_response_t *response)
Get response body as JSON text.
Definition fetch.c:8350
const char * fetch_response_text(fetch_response_t *response)
Get response body as text.
Definition fetch.c:8329
const char * fetch_response_status_text(const fetch_response_t *response)
Get HTTP status text.
Definition fetch.c:8377
const char * fetch_response_url(const fetch_response_t *response)
Get final URL (after redirects)
Definition fetch.c:8381
uint16_t fetch_response_status(const fetch_response_t *response)
Get HTTP status code.
Definition fetch.c:8373
struct fetch_response fetch_response_t
HTTP response object.
void fetch_url_search_params_delete(fetch_url_search_params_t *params, const char *name)
Remove all parameters with the given name.
Definition fetch.c:8617
void fetch_url_search_params_append(fetch_url_search_params_t *params, const char *name, const char *value)
Add a parameter (allows duplicates)
Definition fetch.c:8578
bool fetch_url_search_params_has(const fetch_url_search_params_t *params, const char *name)
Check if a parameter exists.
Definition fetch.c:8655
fetch_url_search_params_t * fetch_url_search_params_new(void)
Create a new URL search parameters container.
Definition fetch.c:8505
bool fetch_url_search_params_next(fetch_url_search_params_iterator_t *iter, const char **key, const char **value)
Get the next parameter from an iterator.
Definition fetch.c:8818
void fetch_url_search_params_set(fetch_url_search_params_t *params, const char *name, const char *value)
Set a parameter (replaces existing)
Definition fetch.c:8601
const char * fetch_url_search_params_get(const fetch_url_search_params_t *params, const char *name)
Get the first parameter value with the given name.
Definition fetch.c:8641
fetch_url_search_params_iterator_t fetch_url_search_params_entries(const fetch_url_search_params_t *params)
Create an iterator for URL search parameters.
Definition fetch.c:8812
void fetch_url_search_params_free(fetch_url_search_params_t *params)
Free a URL search parameters container.
Definition fetch.c:8538
char * fetch_url_search_params_to_string(const fetch_url_search_params_t *params)
Convert parameters to URL-encoded string.
Definition fetch.c:8661
struct fetch_url_search_params fetch_url_search_params_t
URL search parameters container.
http_method_t fetch_method_from_string(const char *method_str)
Convert string to HTTP method enum.
Definition fetch.c:9077
const char * fetch_error_to_string(fetch_error_t error)
Convert error code to human-readable string.
Definition fetch.c:9114
const char * fetch_method_to_string(http_method_t method)
Convert HTTP method enum to string.
Definition fetch.c:9052
bool fetch_is_valid_url(const char *url)
Check if a URL is valid.
Definition fetch.c:9103
static int fetch_version_minor(void)
Get minor version number at runtime.
Definition fetch.h:157
static bool fetch_version_at_least(int major, int minor, int patch)
Check if current version is at least the specified version.
Definition fetch.h:185
static const char * fetch_version_string(void)
Get clean semantic version at runtime.
Definition fetch.h:143
static int fetch_version_major(void)
Get major version number at runtime.
Definition fetch.h:151
static int fetch_version_patch(void)
Get patch version number at runtime.
Definition fetch.h:163
static int fetch_version_compare(int major, int minor, int patch)
Compare version against another version.
Definition fetch.h:172
static const char * fetch_version(void)
Get version information at runtime.
Definition fetch.h:137
Cookie jar implementation.
Definition cookie.h:184
Abort controller for cancelling requests.
Definition fetch.h:371
const char * reason
Definition fetch.h:373
void(* on_abort)(void *userdata)
Definition fetch.h:374
bool aborted
Definition fetch.h:372
void * userdata
Definition fetch.h:375
Request or response body.
Definition fetch.h:441
const char * content_type
Definition fetch.h:463
fetch_file_continue_cb continue_cb
Definition fetch.h:458
size_t size
Definition fetch.h:448
void * userdata
Definition fetch.h:459
bool close_on_free
Definition fetch.h:456
FETCH_FILE_HANDLE handle
Definition fetch.h:453
size_t offset
Definition fetch.h:455
const void * data
Definition fetch.h:447
fetch_body_type_t type
Definition fetch.h:442
Global configuration for the fetch library.
Definition fetch.h:1818
const char * origin
Definition fetch.h:1820
uint32_t max_pooled_connections
Definition fetch.h:1829
uint32_t max_connections_per_host
Definition fetch.h:1826
uint32_t flags
Definition fetch.h:1831
const char * user_agent
Definition fetch.h:1819
uint32_t default_timeout_ms
Definition fetch.h:1824
uint32_t pool_cleanup_interval_ms
Definition fetch.h:1828
uint32_t keep_alive_timeout_ms
Definition fetch.h:1827
cookie_jar_t * cookie_jar
Definition fetch.h:1822
uint32_t max_connections
Definition fetch.h:1825
Definition fetch.c:618
Iterator for traversing headers.
Definition fetch.h:403
size_t index
Definition fetch.h:405
const fetch_headers_t * headers
Definition fetch.h:404
HTTP headers container.
Definition fetch.h:393
size_t capacity
Definition fetch.h:397
size_t count
Definition fetch.h:396
char ** values
Definition fetch.h:395
char ** keys
Definition fetch.h:394
Request configuration options.
Definition fetch.h:482
const char * referrer_policy
Definition fetch.h:491
fetch_mode_t mode
Definition fetch.h:486
const char * referrer
Definition fetch.h:490
uint32_t timeout_ms
Definition fetch.h:496
fetch_credentials_t credentials
Definition fetch.h:487
fetch_headers_t * headers
Definition fetch.h:484
bool keepalive
Definition fetch.h:493
const char * integrity
Definition fetch.h:492
fetch_body_t * body
Definition fetch.h:485
http_method_t method
Definition fetch.h:483
fetch_abort_controller_t * signal
Definition fetch.h:495
uint32_t max_redirects
Definition fetch.h:497
fetch_cache_t cache
Definition fetch.h:488
fetch_redirect_t redirect
Definition fetch.h:489
Promise for asynchronous fetch operations.
Definition fetch.h:563
fetch_promise_state_t state
Definition fetch.h:565
const char * error_message
Definition fetch.h:568
volatile bool detached
Definition fetch.h:575
void * userdata
Definition fetch.h:572
fetch_on_rejected_cb on_rejected
Definition fetch.h:571
uint64_t promise_id
Definition fetch.h:564
void * internal_state
Definition fetch.h:574
fetch_error_t error
Definition fetch.h:567
fetch_response_t * response
Definition fetch.h:566
fetch_on_fulfilled_cb on_fulfilled
Definition fetch.h:570
HTTP response object.
Definition fetch.h:515
fetch_error_t error
Definition fetch.h:525
const char * url
Definition fetch.h:520
void * body
Definition fetch.h:522
const char * status_text
Definition fetch.h:517
const char * error_message
Definition fetch.h:526
fetch_headers_t * headers
Definition fetch.h:521
fetch_body_type_t body_type
Definition fetch.h:524
uint16_t status
Definition fetch.h:516
bool redirected
Definition fetch.h:519
bool ok
Definition fetch.h:518
size_t body_size
Definition fetch.h:523
Iterator for URL search parameters.
Definition fetch.h:604
const fetch_url_search_params_t * params
Definition fetch.h:605
size_t index
Definition fetch.h:606
URL search parameters container.
Definition fetch.h:594
size_t count
Definition fetch.h:597
char ** keys
Definition fetch.h:595
char ** values
Definition fetch.h:596
size_t capacity
Definition fetch.h:598