Header store#
Stores header fields back to back as NUL-terminated name and value pairs in a caller-supplied buffer. Lookups are case-insensitive and return the first match.
-
struct lwhttp_headers_t#
Header store: name/value pairs packed into a caller-supplied buffer.
Each field takes
strlen(name) + strlen(value) + 2bytes. Lookups are case-insensitive and duplicate names are kept as separate entries in insertion order. Initialise withlwhttp_headers_init(); the fields are read-only for applications.-
char *data#
Storage buffer.
-
size_t size#
Size of
lwhttp_headers_t.datain bytes.
-
size_t len#
Bytes of
lwhttp_headers_t.datain use.
-
size_t count#
Number of stored fields.
-
char *data#
-
void lwhttp_headers_init(lwhttp_headers_t *headers, char *data, size_t size)#
Initialise an empty header store over a caller-supplied buffer.
- Parameters:
headers – Store to initialise.
data – Storage buffer; must stay valid while the store is used.
size – Size of
datain bytes.
-
void lwhttp_headers_clear(lwhttp_headers_t *headers)#
Remove all fields. The buffer is kept and pointers previously returned become stale.
- Parameters:
headers – The store.
-
lwhttp_error_t lwhttp_headers_add(lwhttp_headers_t *headers, const char *name, const char *value)#
Append a copy of a field. Names and values are not validated, and existing fields with the same name are kept.
- Parameters:
headers – The store.
name – NUL-terminated field name.
value – NUL-terminated field value.
- Returns:
LWHTTP_OK, orLWHTTP_ERR_HEADERS_TOO_LARGEif it does not fit (the store is unchanged).
-
const char *lwhttp_headers_get(const lwhttp_headers_t *headers, const char *name)#
Find the first field with a given name, ignoring case.
- Parameters:
headers – The store, may be
NULL.name – Field name, may be
NULL.
- Returns:
NUL-terminated value inside the store, or
NULLif absent or an argument isNULL. Valid until the store is cleared or its buffer reused.
-
bool lwhttp_headers_at(const lwhttp_headers_t *headers, size_t index, const char **name, const char **value)#
Get a field by position, in insertion order. Use it to read repeated fields such as
Set-Cookie.- Parameters:
headers – The store, may be
NULL.index – Zero-based position.
name – Receives the NUL-terminated name, or
NULLif not wanted.value – Receives the NUL-terminated value, or
NULLif not wanted.
- Returns:
true on success; false if
indexis out of range orheadersisNULL.
-
size_t lwhttp_headers_count(const lwhttp_headers_t *headers)#
Number of stored fields.
- Parameters:
headers – The store, may be
NULL.
- Returns:
Field count, 0 for
NULL.