|
KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
|
Built-in CORS middleware. More...


Go to the source code of this file.
Data Structures | |
| struct | KlCorsConfig |
Macros | |
| #define | KL_CORS_MAX_ORIGINS 16 |
| Maximum number of allowed origins. | |
| #define | KL_CORS_ORIGIN_SIZE 256 |
| Maximum origin string length. | |
Functions | |
| void | kl_cors_init (KlCorsConfig *config) |
| Initialize CORS config with defaults. Allows all origins (*), standard methods/headers, 24h preflight cache. | |
| int | kl_cors_add_origin (KlCorsConfig *config, const char *origin) |
| Add an allowed origin. If no origins are added, all origins are allowed (*). Once at least one origin is added, only those origins are allowed. | |
| int | kl_cors_parse_origins (KlCorsConfig *config, const char *origins) |
| Parse comma-separated origins and add them. Useful for parsing from environment variables. | |
| int | kl_cors_is_allowed (const KlCorsConfig *config, const char *origin, size_t origin_len) |
| Check if an origin is allowed by the config. | |
| int | kl_cors_middleware (KlRequest *req, KlResponse *res, void *user_data) |
| CORS middleware function. Pass a KlCorsConfig* as user_data when registering. | |
Built-in CORS middleware.
Usage:
| #define KL_CORS_MAX_ORIGINS 16 |
Maximum number of allowed origins.
| #define KL_CORS_ORIGIN_SIZE 256 |
Maximum origin string length.
| void kl_cors_init | ( | KlCorsConfig * | config | ) |
Initialize CORS config with defaults. Allows all origins (*), standard methods/headers, 24h preflight cache.
| int kl_cors_add_origin | ( | KlCorsConfig * | config, |
| const char * | origin | ||
| ) |
Add an allowed origin. If no origins are added, all origins are allowed (*). Once at least one origin is added, only those origins are allowed.
| int kl_cors_parse_origins | ( | KlCorsConfig * | config, |
| const char * | origins | ||
| ) |
Parse comma-separated origins and add them. Useful for parsing from environment variables.
| int kl_cors_is_allowed | ( | const KlCorsConfig * | config, |
| const char * | origin, | ||
| size_t | origin_len | ||
| ) |
Check if an origin is allowed by the config.
| int kl_cors_middleware | ( | KlRequest * | req, |
| KlResponse * | res, | ||
| void * | user_data | ||
| ) |
CORS middleware function. Pass a KlCorsConfig* as user_data when registering.
For OPTIONS requests: sends 204 with preflight headers, short-circuits. For other requests: adds Access-Control-Allow-Origin and continues.