KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
cors.h
Go to the documentation of this file.
1#ifndef KEEL_CORS_H
2#define KEEL_CORS_H
3
4#include <keel/request.h>
5#include <keel/response.h>
6#include <stddef.h>
7
21#define KL_CORS_MAX_ORIGINS 16
23#define KL_CORS_ORIGIN_SIZE 256
24
33
39
46int kl_cors_add_origin(KlCorsConfig *config, const char *origin);
47
53int kl_cors_parse_origins(KlCorsConfig *config, const char *origins);
54
59int kl_cors_is_allowed(const KlCorsConfig *config, const char *origin,
60 size_t origin_len);
61
71int kl_cors_middleware(KlRequest *req, KlResponse *res, void *user_data);
72
73#endif
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_middleware(KlRequest *req, KlResponse *res, void *user_data)
CORS middleware function. Pass a KlCorsConfig* as user_data when registering.
int kl_cors_is_allowed(const KlCorsConfig *config, const char *origin, size_t origin_len)
Check if an origin is allowed by the config.
#define KL_CORS_ORIGIN_SIZE
Maximum origin string length.
Definition cors.h:23
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...
void kl_cors_init(KlCorsConfig *config)
Initialize CORS config with defaults. Allows all origins (*), standard methods/headers,...
#define KL_CORS_MAX_ORIGINS
Maximum number of allowed origins.
Definition cors.h:21
Definition cors.h:25
int origin_count
Definition cors.h:27
const char * allowed_methods
Definition cors.h:28
int max_age_seconds
Definition cors.h:31
const char * allowed_headers
Definition cors.h:29
int allow_credentials
Definition cors.h:30
Definition request.h:26
Definition response.h:21