BSB Developer Docs
Loading...
Searching...
No Matches
http_headers.h File Reference

Utility functions for dealing with HTTP headers. More...

#include <core/string.h>

Go to the source code of this file.

Data Structures

struct  HttpHeader
 Single HTTP header structure (key: value). More...
 

Typedefs

typedef struct HttpHeader HttpHeader
 Single HTTP header structure (key: value).
 

Functions

HttpHeaders * http_headers_alloc (void)
 Create an empty HttpHeaders instance.
 
void http_headers_free (HttpHeaders *instance)
 Delete the HttpHeaders instance.
 
bool http_headers_parse (HttpHeaders *instance, const char *data, size_t data_len)
 Parse the HTTP headers from a string.
 
size_t http_headers_get_count (const HttpHeaders *instance)
 Get the number of header elements held in the instance.
 
const HttpHeader * http_headers_get_by_index (const HttpHeaders *instance, size_t index)
 Get the header element by its index.
 
const HttpHeader * http_headers_get (const HttpHeaders *instance, const char *key)
 Get the header element by its string key.
 
void http_headers_set (HttpHeaders *instance, const char *key, const char *value)
 Set the header element under the string key.
 

Detailed Description

Utility functions for dealing with HTTP headers.

Function Documentation

◆ http_headers_alloc()

HttpHeaders * http_headers_alloc ( void )

Create an empty HttpHeaders instance.

Returns
pointer to the created instance

◆ http_headers_free()

void http_headers_free ( HttpHeaders * instance)

Delete the HttpHeaders instance.

Parameters
[in,out]instancepointer to the instance to be deleted

◆ http_headers_get()

const HttpHeader * http_headers_get ( const HttpHeaders * instance,
const char * key )

Get the header element by its string key.

The key string is case-insensitive (i.e. "KeY" and "key" are treated the same).

Note
The return value will become invalid after modfying the instance with parse() or set() functions or deleting it using http_headers_free().
Parameters
[in]instancepointer to the instance to be queried
[in]keyzero-terminated string containing the header name (key)
Returns
pointer to the element at the requested key or NULL if none exists

◆ http_headers_get_by_index()

const HttpHeader * http_headers_get_by_index ( const HttpHeaders * instance,
size_t index )

Get the header element by its index.

Note
The return value will become invalid after modfying the instance with parse() or set() functions or deleting it using http_headers_free().
Parameters
[in]instancepointer to the instance to be queried
[in]indexthe desired element index (must be < total number of elements)
Returns
pointer to the element at the requested index

◆ http_headers_get_count()

size_t http_headers_get_count ( const HttpHeaders * instance)

Get the number of header elements held in the instance.

Parameters
[in]instancepointer to the instance to be queried
Returns
number of elements currently held in the instance

◆ http_headers_parse()

bool http_headers_parse ( HttpHeaders * instance,
const char * data,
size_t data_len )

Parse the HTTP headers from a string.

Parameters
[in,out]instancepointer to the instance to hold the parsing results
[in]datapointer to the source string (not required to be zero-terminated)
[in]data_lenlength of the source string in bytes
Returns
true if the input data could be parsed, false otherwise

◆ http_headers_set()

void http_headers_set ( HttpHeaders * instance,
const char * key,
const char * value )

Set the header element under the string key.

The key string is case-insensitive (i.e. "KeY" and "key" are treated the same).

If an element already exists under the provided key, its value will be replaced with the new one, otherwise a new element will be inserted.

Parameters
[in,out]instancepointer to the instance to be modified
[in]keyzero-terminated string containing the header name (key)
[in]valuezero-terminated string containing the value