Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
cors.c File Reference

CORS middleware implementation. More...

#include <stdio.h>
#include <string.h>
#include "csilk/core/internal.h"
#include "csilk/csilk.h"
Include dependency graph for cors.c:

Functions

void csilk_cors_middleware (csilk_ctx_t *c, const csilk_cors_config_t *config)
 CORS middleware — sets cross-origin headers and handles preflight requests.
 

Detailed Description

CORS middleware implementation.

Function Documentation

◆ csilk_cors_middleware()

void csilk_cors_middleware ( csilk_ctx_t *  c,
const csilk_cors_config_t config 
)

CORS middleware — sets cross-origin headers and handles preflight requests.

CORS middleware — handles preflight and adds CORS headers.

Applies the configured Access-Control-* headers to every response. When the Vary: Origin header is set for non-wildcard origins. If the incoming request is an OPTIONS preflight (indicated by Access-Control-Request-Method), the middleware short-circuits with a 204 No Content response instead of forwarding to downstream handlers.

Parameters
cThe request context.
configPointer to a CORS configuration struct specifying allowed origins, methods, headers, credentials, and max-age. Must remain valid for the duration of the call.
Note
This middleware always calls csilk_next() for non-preflight requests after setting response headers.
Warning
The config pointer is not deep-copied; the caller must ensure it lives long enough for the current request.