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
type
| SYMBOL | DESCRIPTION |
|---|---|
| http_t | Global library struct. Implemented here http. |
include
| SYMBOL | DESCRIPTION |
|---|---|
| <so/sock.h> |
macro
const
| SYMBOL | DESCRIPTION |
|---|
enum
| SYMBOL | DESCRIPTION |
|---|---|
| http_err_t | Error code. |
| http_status_t | HTTP status code. |
struct
| SYMBOL | DESCRIPTION |
|---|---|
| http_host_t | Represents a the host. |
| http_bind_t | Represents a the binding (port). |
| http_conn_t | Represents a client connection. |
| http_header_t | A HTTP header. |
| http_req_t | A HTTP request struct. |
| http_resp_t | A HTTP response struct. |
| 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. |
| http_route_t | A route. |
| http_pair_t | |
| http_pairs_t | |
| http | Implementation of the global library struct. Type here http_t. |
union
| SYMBOL | DESCRIPTION |
|---|
func
| SYMBOL | DESCRIPTION |
|---|---|
| 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_on_route | Registers a new route. Use macros like HTTP_GET and others to register routes more easily. |
| http_on_default | Registers a fallback handler. Use macro HTTP_DEFAULT instead. |
| http_on_pre_route | Registers a middleware handler which is performed before the route handler is executed. Use macro HTTP_MIDDLEWARE_PRE instead. |
| http_on_post_route | Registers a middleware handler which is performed after the route handler is executed. Use macro HTTP_MIDDLEWARE_POST instead. |
| http_req_path | |
| http_req_body | |
| http_req_queries | |
| http_req_params | |
| http_pairs_get | |
| http_pairs_has | |
| http_pairs_free | |
| http_req_header | |
| http_resp_header | |
| http_resp_create | |
| http_resp_body | |
| http_req_free | |
| http_resp_write_head | |
| http_resp_write_body | |
| http_resp_write | |
| http_resp_free | |
| http_bind | |
| http_listen | |
| http_bind_listen | |
| http_close | |
| _http_read_req | |
| _http_on_global | The default route handler. Can be overwritten with http_on_global. |
http_t
func http_init (http.h:202)
Initializes global library context http_t. Free with http_cleanup.
http_t *http_init(void);
func http_cleanup (http.h:208)
Cleans up http_t.
- [param] http_t *self - The global library context.
void http_cleanup(http_t *self);
func http_on_global (http.h:215)
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_bind (http.h:310)
- [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:315)
- [param] http_t *self - The global library context.
http_err_t http_listen(http_t *self);
func http_bind_listen (http.h:322)
- [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:327)
- [param] http_t *self - The global library context.
void http_close(http_t *self);
func _http_on_global (http.h:432) [internal]
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.
[RET] http_resp_t Returns a HTTP response.
http_resp_t _http_on_global(http_t *self, http_req_t *req) {
http_req_t
struct http_req_t (http.h:135)
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;
func http_req_path (http.h:241)
char *http_req_path(http_req_t *req);
func http_req_body (http.h:245)
char *http_req_body(http_req_t *req);
func http_req_queries (http.h:249)
http_pairs_t http_req_queries(http_req_t *req);
func http_req_params (http.h:253)
http_pairs_t http_req_params(http_req_t *req);
func http_req_header (http.h:269)
char *http_req_header(http_req_t *req, char *key);
func http_req_free (http.h:285)
void http_req_free(http_req_t *req);
http_resp_t
struct http_resp_t (http.h:150)
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;
func http_resp_header (http.h:273)
void http_resp_header(http_resp_t *resp, char *key, char *value);
func http_resp_create (http.h:277)
http_resp_t http_resp_create(http_status_t status);
func http_resp_body (http.h:281)
void http_resp_body(http_resp_t *resp, char *body, long len);
func http_resp_write_head (http.h:289)
void http_resp_write_head(http_conn_t *conn, http_resp_t *resp);
func http_resp_write_body (http.h:293)
void http_resp_write_body(http_conn_t *conn, http_resp_t *resp);
func http_resp_write (http.h:297)
void http_resp_write(http_conn_t *conn, http_resp_t *resp);
func http_resp_free (http.h:301)
void http_resp_free(http_resp_t *resp);
http_pairs_t
struct http_pairs_t (http.h:187)
typedef struct {
http_pair_t *pairs;
size_t len;
} http_pairs_t;
func http_pairs_get (http.h:257)
char *http_pairs_get(http_pairs_t *self, char *key);
func http_pairs_has (http.h:261)
bool http_pairs_has(http_pairs_t *self, char *key);
func http_pairs_free (http.h:265)
void http_pairs_free(http_pairs_t *self);
type
include
include <so/sock.h> (http.h:32)
#include <so/sock.h>
macro
macro HTTP_RESP_HANDLED (http.h:355)
Handled http_resp_t.
#define HTTP_RESP_HANDLED (http_resp_t) { .status = __HTTP_STATUS_HANDLED }
macro HTTP_GET (http.h:366)
#define HTTP_GET(path, fn_name) _HTTP_ON("GET", path, fn_name)
macro HTTP_GET (http.h:369)
#define HTTP_HEAD(path, fn_name) _HTTP_ON("HEAD", path, fn_name)
macro HTTP_POST (http.h:372)
#define HTTP_POST(path, fn_name) _HTTP_ON("POST", path, fn_name)
macro HTTP_PUT (http.h:375)
#define HTTP_PUT(path, fn_name) _HTTP_ON("PUT", path, fn_name)
macro HTTP_DELETE (http.h:378)
#define HTTP_DELETE(path, fn_name) _HTTP_ON("DELETE", path, fn_name)
macro HTTP_CONNECT (http.h:381)
#define HTTP_CONNECT(path, fn_name) _HTTP_ON("CONNECT", path, fn_name)
macro HTTP_OPTIONS (http.h:384)
#define HTTP_OPTIONS(path, fn_name) _HTTP_ON("OPTIONS", path, fn_name)
macro HTTP_TRACE (http.h:387)
#define HTTP_TRACE(path, fn_name) _HTTP_ON("TRACE", path, fn_name)
macro HTTP_PATCH (http.h:390)
#define HTTP_PATCH(path, fn_name) _HTTP_ON("PATCH", path, fn_name)
macro HTTP_DEFAULT (http.h:393)
#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_MIDDLEWARE_PRE (http.h:402)
#define HTTP_MIDDLEWARE_PRE(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_MIDDLEWARE_POST (http.h:411)
#define HTTP_MIDDLEWARE_POST(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)
const
enum
enum http_err_t (http.h:36)
Error code.
typedef enum {
HTTP_ERR_OK = SOCK_ERR_OK,
HTTP_ERR__COUNT,
} http_err_t;
enum http_status_t (http.h:43)
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;
struct
struct http_header_t (http.h:127)
A HTTP header.
typedef struct {
char *key;
char *value;
} http_header_t;
struct http_global_fn_t (http.h:161)
A function type for a global route handler.
typedef http_resp_t (*http_global_fn_t)(http_t *, http_req_t *);
struct http_handle_fn_t (http.h:165)
A function type for a route handler.
typedef http_resp_t (*http_handle_fn_t)(http_req_t *);
struct http_hook_fn_t (http.h:169)
A function type for a hook handler.
typedef void (*http_hook_fn_t)(http_req_t *);
struct http_route_t (http.h:173)
A route.
typedef struct {
char *method;
char *path;
http_handle_fn_t fn;
} http_route_t;
struct http_pair_t (http.h:180)
typedef struct {
char *key;
char *value;
} http_pair_t;
struct http (http.h:194)
Implementation of the global library struct. Type here http_t.
struct http {
sock_t *sock;
http_global_fn_t fn;
};
union
func
func http_on_route (http.h:222)
Registers a new route. Use macros like HTTP_GET and others to register routes more easily.
- [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:227)
Registers a fallback handler. Use macro HTTP_DEFAULT instead.
- [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:232)
Registers a middleware handler which is performed before the route handler is executed. Use macro HTTP_MIDDLEWARE_PRE instead.
- [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:237)
Registers a middleware handler which is performed after the route handler is executed. Use macro HTTP_MIDDLEWARE_POST instead.
- [param] http_hook_fn_t fn - The hook handler.
void http_on_post_route(http_hook_fn_t fn);
func _http_read_req (http.h:331) [internal]
http_err_t _http_read_req(http_conn_t *conn, http_req_t *req);