Hi there! I'm Sophie, and welcome to my own little place on the internet.
I'm a self-thought programmer who likes to travel and learn new stuff. I enjoy listening to music, being outside in nature, and having a chat with a good cup of coffee.
I'm currently working as an SAP E-Commerce Consultant at innovate Software GmbH. My expertise lies in developing custom-tailored software solutions for the SAP Commerce ecosystem.
You can get in touch with me via E-mail: info@soophie.de
API Reference
http_t
# type http_t (http.h:115)
Global context struct. Implemented here http.
typedef struct http http_t;
Structs
| http | Implementation of the global context struct. Type here http_t. |
Functions
| http_init | Initializes global library context http_t. Free with http_cleanup. |
| http_cleanup | Cleans up http_t. |
| http_on_global | Set and override the default global route handler _http_on_global. |
| http_bind | |
| http_listen | |
| http_bind_listen | |
| http_close | |
| internal _http_on_global | The default route handler. Can be overwritten with http_on_global. |
http_conn_t
Functions
| internal _http_conn_read | |
| internal _http_conn_write |
http_req_t
# struct http_req_t (http.h:140)
A HTTP request struct.
typedef struct {
http_conn_t *conn;
char *method;
char *url;
char *version;
http_header_t *headers;
int headers_len;
char *body;
long body_len;
void *ext_data;
} http_req_t;
Functions
| http_req_path | |
| http_req_body | |
| http_req_queries | |
| http_req_params | |
| http_req_header | |
| http_req_free | Frees a request. |
| internal _http_req_read |
http_resp_t
# struct http_resp_t (http.h:155)
A HTTP response struct.
typedef struct {
char *version;
http_status_t status;
http_header_t *headers;
int headers_len;
char *body;
long body_len;
} http_resp_t;
Macros
| HTTP_RESP_HANDLED | Handled http_resp_t. |
Functions
| http_resp_header | Writes a header to the response. The header content is consumed and can be freed afterward. |
| http_resp_create | Creates a new response with a given HTTP status. Freed with http_resp_free. |
| http_resp_body | Writes body content to the response. The body content is consumed and can be freed afterward. |
| http_resp_write_head | Writes a response header to the socket stream. |
| http_resp_write_body | Writes a response body to the socket stream. |
| http_resp_write | Writes a response to the socket stream. |
| http_resp_free | Frees a response. |
http_pairs_t
# struct http_pairs_t (http.h:192)
typedef struct {
http_pair_t *pairs;
size_t len;
} http_pairs_t;
Functions
| http_pairs_get | |
| http_pairs_has | |
| http_pairs_free | |
| internal _http_pairs_init |
Types
| http_host_t | Represents a the host. |
| http_bind_t | Represents a the binding (port). |
| http_global_fn_t | A function type for a global route handler. |
| http_handle_fn_t | A function type for a route handler. |
| http_hook_fn_t | A function type for a hook handler. |
Includes
| <openssl/ssl.h> | OpenSSL library handling TLS/SSL. |
| <so/sock.h> | so/sock library handling server/client communication and multi-threading. |
Macros
Consts
No definitions.Globals
| internal _http_routes | |
| internal _http_routes_len | |
| internal _http_default_route | |
| internal _http_pre_route | |
| internal _http_post_route |
Enums
| http_err_t | Error code. |
| http_status_t | HTTP status code. |
Structs
| http_header_t | A HTTP header. |
| http_route_t | A route. |
| http_pair_t |
Unions
No definitions.Functions
| http_on_route | Registers a new route. |
| http_on_default | Registers a fallback handler. |
| http_on_pre_route | Registers a hook handler which is performed before the route handler is executed. |
| http_on_post_route | Registers a hook handler which is performed after the route handler is executed. |
| internal _http_on_handle | |
| internal _http_pair_decode | |
| internal _http_status_str |
Types
# type http_global_fn_t (http.h:166)
A function type for a global route handler.
typedef http_resp_t (*http_global_fn_t)(http_t *, http_req_t *);
# type http_handle_fn_t (http.h:170)
A function type for a route handler.
typedef http_resp_t (*http_handle_fn_t)(http_req_t *);
# type http_hook_fn_t (http.h:174)
A function type for a hook handler.
typedef void (*http_hook_fn_t)(http_req_t *);
Includes
# include <so/sock.h> (http.h:36)
so/sock library handling server/client communication and multi-threading.
#include <so/sock.h>
Macros
# macro internal HTTP_VERSION (http.h:399)
#define HTTP_VERSION "HTTP/1.1"
# macro internal HTTP_MAX_REQUEST_HEAD_SIZE (http.h:403)
#define HTTP_MAX_REQUEST_HEAD_SIZE 1000000
# macro HTTP_RESP_HANDLED (http.h:408)
Handled http_resp_t.
#define HTTP_RESP_HANDLED (http_resp_t) { .status = __HTTP_STATUS_HANDLED }
# macro internal _HTTP_ON (http.h:412)
#define _HTTP_ON(method, path, fn_name) \
static http_resp_t fn_name(http_req_t *req); \
__attribute__((constructor)) \
static void __macro_http_fn_register_##fn_name() { \
http_on_route(method, path, &fn_name); \
} \
static http_resp_t fn_name(http_req_t *req)
# macro HTTP_GET (http.h:421)
#define HTTP_GET(path, fn_name) _HTTP_ON("GET", path, fn_name)
# macro HTTP_GET (http.h:424)
#define HTTP_HEAD(path, fn_name) _HTTP_ON("HEAD", path, fn_name)
# macro HTTP_POST (http.h:427)
#define HTTP_POST(path, fn_name) _HTTP_ON("POST", path, fn_name)
# macro HTTP_PUT (http.h:430)
#define HTTP_PUT(path, fn_name) _HTTP_ON("PUT", path, fn_name)
# macro HTTP_DELETE (http.h:433)
#define HTTP_DELETE(path, fn_name) _HTTP_ON("DELETE", path, fn_name)
# macro HTTP_CONNECT (http.h:436)
#define HTTP_CONNECT(path, fn_name) _HTTP_ON("CONNECT", path, fn_name)
# macro HTTP_OPTIONS (http.h:439)
#define HTTP_OPTIONS(path, fn_name) _HTTP_ON("OPTIONS", path, fn_name)
# macro HTTP_TRACE (http.h:442)
#define HTTP_TRACE(path, fn_name) _HTTP_ON("TRACE", path, fn_name)
# macro HTTP_PATCH (http.h:445)
#define HTTP_PATCH(path, fn_name) _HTTP_ON("PATCH", path, fn_name)
# macro HTTP_DEFAULT (http.h:448)
#define HTTP_DEFAULT(fn_name) \
static http_resp_t fn_name(http_req_t *req); \
__attribute__((constructor)) \
static void __macro_http_fn_register_##fn_name() { \
http_on_default(&fn_name); \
} \
static http_resp_t fn_name(http_req_t *req)
# macro HTTP_PRE_HOOK (http.h:457)
#define HTTP_PRE_HOOK(fn_name) \
static void fn_name(http_req_t *req); \
__attribute__((constructor)) \
static void __macro_http_fn_register_##fn_name() { \
http_on_pre_route(&fn_name); \
} \
static void fn_name(http_req_t *req)
# macro HTTP_POST_HOOK (http.h:466)
#define HTTP_POST_HOOK(fn_name) \
static void fn_name(http_req_t *req); \
__attribute__((constructor)) \
static void __macro_http_fn_register_##fn_name() { \
http_on_post_route(&fn_name); \
} \
static void fn_name(http_req_t *req)
Consts
No definitions.
Globals
# global internal _http_routes (http.h:476)
http_route_t *_http_routes = NULL;
# global internal _http_routes_len (http.h:480)
size_t _http_routes_len = 0;
# global internal _http_default_route (http.h:484)
http_handle_fn_t _http_default_route;
# global internal _http_pre_route (http.h:488)
http_hook_fn_t _http_pre_route;
# global internal _http_post_route (http.h:492)
http_hook_fn_t _http_post_route;
Enums
# enum http_err_t (http.h:40)
Error code.
typedef enum {
HTTP_ERR_OK = SOCK_ERR_OK,
HTTP_ERR__COUNT,
} http_err_t;
# enum http_status_t (http.h:47)
HTTP status code.
typedef enum {
HTTP_STATUS_CONTINUE = 100,
HTTP_STATUS_SWITCHING_PROTOCOLS = 101,
HTTP_STATUS_PROCESSING = 102,
HTTP_STATUS_EARLY_HINTS = 103,
HTTP_STATUS_OK = 200,
HTTP_STATUS_CREATED = 201,
HTTP_STATUS_ACCEPTED = 202,
HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203,
HTTP_STATUS_NO_CONTENT = 204,
HTTP_STATUS_RESET_CONTENT = 205,
HTTP_STATUS_PARTIAL_CONTENT = 206,
HTTP_STATUS_MULTI_STATUS = 207,
HTTP_STATUS_ALREADY_REPORTED = 208,
HTTP_STATUS_IM_USED = 226,
HTTP_STATUS_MULTIPLE_CHOICES = 300,
HTTP_STATUS_MOVED_PERMANENTLY = 301,
HTTP_STATUS_FOUND = 302,
HTTP_STATUS_SEE_OTHER = 303,
HTTP_STATUS_NOT_MODIFIED = 304,
HTTP_STATUS_TEMPORARY_REDIRECT = 307,
HTTP_STATUS_PERMANENT_REDIRECT = 308,
HTTP_STATUS_BAD_REQUEST = 400,
HTTP_STATUS_UNAUTHORIZED = 401,
HTTP_STATUS_PAYMENT_REQUIRED = 402,
HTTP_STATUS_FORBIDDEN = 403,
HTTP_STATUS_NOT_FOUND = 404,
HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
HTTP_STATUS_NOT_ACCEPTABLE = 406,
HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407,
HTTP_STATUS_REQUEST_TIMEOUT = 408,
HTTP_STATUS_CONFLICT = 409,
HTTP_STATUS_GONE = 410,
HTTP_STATUS_LENGTH_REQUIRED = 411,
HTTP_STATUS_PRECONDITION_FAILED = 412,
HTTP_STATUS_PAYLOAD_TOO_LARGE = 413,
HTTP_STATUS_URI_TOO_LONG = 414,
HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416,
HTTP_STATUS_EXPECTATION_FAILED = 417,
HTTP_STATUS_I_AM_A_TEAPOT = 418,
HTTP_STATUS_MISDIRECTED_REQUEST = 421,
HTTP_STATUS_UNPROCESSABLE_CONTENT = 422,
HTTP_STATUS_LOCKED = 423,
HTTP_STATUS_FAILED_DEPENDENCY = 424,
HTTP_STATUS_TOO_EARLY = 425,
HTTP_STATUS_UPGRADE_REQUIRED = 426,
HTTP_STATUS_PRECONDITION_REQUIRED = 428,
HTTP_STATUS_TOO_MANY_REQUESTS = 429,
HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
HTTP_STATUS_NOT_IMPLEMENTED = 501,
HTTP_STATUS_BAD_GATEWAY = 502,
HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
HTTP_STATUS_GATEWAY_TIMEOUT = 504,
HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED = 505,
HTTP_STATUS_VARIANT_ALSO_NEGOTITATES = 506,
HTTP_STATUS_INSUFFICIENT_STORAGE = 507,
HTTP_STATUS_LOOP_DETECTED = 508,
HTTP_STATUS_NOT_EXTENDED = 510,
HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511,
__HTTP_STATUS_HANDLED = 999,
} http_status_t;
Structs
# struct http_header_t (http.h:132)
A HTTP header.
typedef struct {
char *key;
char *value;
} http_header_t;
# struct http_route_t (http.h:178)
A route.
typedef struct {
char *method;
char *path;
http_handle_fn_t fn;
} http_route_t;
# struct http_pair_t (http.h:185)
typedef struct {
char *key;
char *value;
} http_pair_t;
# struct http (http.h:200)
Implementation of the global context struct. Type here http_t.
struct http {
sock_t *sock;
http_global_fn_t fn;
};
Unions
No definitions.
Functions
# func http_init (http.h:209)
Initializes global library context http_t. Free with http_cleanup.
[return] http_t * - Returns the global library context.
http_t *http_init(void);
# func http_cleanup (http.h:215)
Cleans up http_t.
- [param] http_t *self - The global library context.
void http_cleanup(http_t *self);
# func http_on_global (http.h:222)
Set and override the default global route handler _http_on_global.
- [param] http_t *self - The global library context.
- [param] http_global_fn_t fn - The global route handler.
void http_on_global(http_t *self, http_global_fn_t fn);
# func http_on_route (http.h:230)
iUse macros like HTTP_GET and others to register routes more easily.
Registers a new route.
- [param] char *method - The HTTP method.
- [param] char *url - The HTTP URL (path).
- [param] http_handle_fn_t fn - The route handler.
void http_on_route(char *method, char *url, http_handle_fn_t fn);
# func http_on_default (http.h:236)
iUse macro HTTP_DEFAULT instead.
Registers a fallback handler.
- [param] http_handle_fn_t fn - The route handler.
void http_on_default(http_handle_fn_t fn);
# func http_on_pre_route (http.h:242)
iUse macro HTTP_PRE_HOOK instead.
Registers a hook handler which is performed before the route handler is executed.
- [param] http_hook_fn_t fn - The hook handler.
void http_on_pre_route(http_hook_fn_t fn);
# func http_on_post_route (http.h:248)
iUse macro HTTP_POST_HOOK instead.
Registers a hook handler which is performed after the route handler is executed.
- [param] http_hook_fn_t fn - The hook handler.
void http_on_post_route(http_hook_fn_t fn);
# func http_req_path (http.h:254)
- [param] http_req_t *req - The HTTP request.
[return] char * - Returns the request path.
char *http_req_path(http_req_t *req);
# func http_req_body (http.h:260)
- [param] http_req_t *req - The HTTP request.
[return] char * - Returns the request body.
char *http_req_body(http_req_t *req);
# func http_req_queries (http.h:266)
- [param] http_req_t *req - The HTTP request.
[return] http_pairs_t - Returns the request queries.
http_pairs_t http_req_queries(http_req_t *req);
# func http_req_params (http.h:272)
- [param] http_req_t *req - The HTTP request.
[return] http_pairs_t - Returns the request params.
http_pairs_t http_req_params(http_req_t *req);
# func http_pairs_get (http.h:276)
char *http_pairs_get(http_pairs_t *self, char *key);
# func http_pairs_has (http.h:280)
bool http_pairs_has(http_pairs_t *self, char *key);
# func http_pairs_free (http.h:284)
void http_pairs_free(http_pairs_t *self);
# func http_req_header (http.h:291)
- [param] http_req_t *req - The HTTP request.
- [param] char *key - The header key.
[return] char * - Returns a header value.
char *http_req_header(http_req_t *req, char *key);
# func http_resp_header (http.h:299)
Writes a header to the response. The header content is consumed and can be freed afterward.
- [param] http_resp_t *resp - The HTTP response.
- [param] char *key - The header key.
- [param] char *value - The header value.
void http_resp_header(http_resp_t *resp, char *key, char *value);
# func http_resp_create (http.h:306)
Creates a new response with a given HTTP status. Freed with http_resp_free.
- [param] http_status_t status - The HTTP status code.
[return] http_resp_t - Returns a HTTP response.
http_resp_t http_resp_create(http_status_t status);
# func http_resp_body (http.h:314)
Writes body content to the response. The body content is consumed and can be freed afterward.
- [param] http_resp_t *resp - The HTTP response.
- [param] char *body - The body content.
- [param] long len - The body length.
void http_resp_body(http_resp_t *resp, char *body, long len);
# func http_req_free (http.h:320)
Frees a request.
- [param] http_req_t *req - The HTTP request.
void http_req_free(http_req_t *req);
# func http_resp_write_head (http.h:327)
Writes a response header to the socket stream.
- [param] http_resp_t *resp - The HTTP response.
- [param] http_conn_t *conn - The HTTP connection.
void http_resp_write_head(http_resp_t *resp, http_conn_t *conn);
# func http_resp_write_body (http.h:334)
Writes a response body to the socket stream.
- [param] http_resp_t *resp - The HTTP response.
- [param] http_conn_t *conn - The HTTP connection.
void http_resp_write_body(http_resp_t *resp, http_conn_t *conn);
# func http_resp_write (http.h:341)
Writes a response to the socket stream.
- [param] http_resp_t *resp - The HTTP response.
- [param] http_conn_t *conn - The HTTP connection.
void http_resp_write(http_resp_t *resp, http_conn_t *conn);
# func http_resp_free (http.h:347)
Frees a response.
- [param] http_resp_t *resp - The HTTP response.
void http_resp_free(http_resp_t *resp);
# func http_bind (http.h:356)
- [param] http_t *self - The global library context.
- [param] char *hostname - The hostname.
- [param] int port - The port.
- [param] http_host_t *hosts - The host to bind to.
- [param] int hosts_len - The host length of to be bound host.
http_err_t http_bind(http_t *self, char *hostname, int port, http_host_t *hosts, int hosts_len);
# func http_listen (http.h:361)
- [param] http_t *self - The global library context.
http_err_t http_listen(http_t *self);
# func http_bind_listen (http.h:368)
- [param] http_t *self - The global library context.
- [param] char *hostname - The hostname.
- [param] int port - The port.
http_err_t http_bind_listen(http_t *self, char *hostname, int port);
# func http_close (http.h:373)
- [param] http_t *self - The global library context.
void http_close(http_t *self);
# func internal _http_req_read (http.h:381)
- [param] http_req_t *req - The HTTP request.
- [param] http_conn_t *conn - The HTTP connection.
[return] http_err_t - Returns an HTTP error code.
http_err_t _http_req_read(http_req_t *req, http_conn_t *conn);
# func internal _http_on_global (http.h:501)
The default route handler. Can be overwritten with http_on_global.
- [param] http_t *self - The global library context.
- [param] http_req_t *req - The HTTP request.
[return] http_resp_t - Returns a HTTP response.
http_resp_t _http_on_global(http_t *self, http_req_t *req) { ... }
# func internal _http_on_handle (http.h:545)
sock_err_t _http_on_handle(sock_t *sock, http_conn_t *conn) { ... }
# func internal _http_pair_decode (http.h:630)
char *_http_pair_decode(char *str, size_t len) { ... }
# func internal _http_pairs_init (http.h:664)
http_pairs_t _http_pairs_init(char *uri) { ... }
# func internal _http_status_str (http.h:763)
const char *_http_status_str(http_status_t status) { ... }
# func internal _http_conn_read (http.h:895)
ssize_t _http_conn_read(http_conn_t *conn, char *buffer, size_t len) { ... }
# func internal _http_conn_write (http.h:902)
ssize_t _http_conn_write(http_conn_t *conn, char *buffer, size_t len) { ... }