KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
body_reader.h File Reference
#include <keel/allocator.h>
#include <stddef.h>
Include dependency graph for body_reader.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlBodyReader
 
struct  KlBufReader
 Built-in buffer reader — accumulates body into a growable buffer. More...
 

Typedefs

typedef struct KlRequest KlRequest
 Forward declaration — full definition in request.h.
 
typedef struct KlBodyReader KlBodyReader
 Pluggable body reader interface.
 
typedef KlBodyReader *(* KlBodyReaderFactory) (KlAllocator *alloc, const KlRequest *req, void *user_data)
 Factory creates a body reader for a given request.
 

Functions

KlBodyReaderkl_body_reader_buffer (KlAllocator *alloc, const KlRequest *req, void *user_data)
 Factory: create a buffer body reader.
 

Typedef Documentation

◆ KlRequest

typedef struct KlRequest KlRequest

Forward declaration — full definition in request.h.

◆ KlBodyReader

typedef struct KlBodyReader KlBodyReader

Pluggable body reader interface.

The factory receives a fully-parsed KlRequest with valid header pointers. Inspect method, path, Content-Type, Content-Length, etc. in the factory — header pointers into read_buf may be invalidated once the body spans multiple socket reads. Handlers should access body data exclusively through the body reader, not through KlRequest header fields.

◆ KlBodyReaderFactory

typedef KlBodyReader *(* KlBodyReaderFactory) (KlAllocator *alloc, const KlRequest *req, void *user_data)

Factory creates a body reader for a given request.

user_data is the value passed to kl_server_route / kl_router_add. Return NULL to reject the request (KEEL sends 415 and closes).

Function Documentation

◆ kl_body_reader_buffer()

KlBodyReader * kl_body_reader_buffer ( KlAllocator alloc,
const KlRequest req,
void *  user_data 
)

Factory: create a buffer body reader.

Pass max_size as user_data via cast: (void *)(size_t)max_size. Pass NULL (0) for unlimited.

Parameters
allocAllocator for buffer growth.
reqParsed request (headers inspectable).
user_dataCast to size_t max_size limit.
Returns
Body reader, or NULL on allocation failure.