This is my attempt at creating an Async HTTP Server in C, it's only planned to work on linux_x86
and only on more "modern" kernel versions (5.6+), here is a simple example on how to use it along with
cJSON:
char *GetUsers(Request *req, Response *res) {
cJSON *users_array = cJSON_CreateArray();
for (size_t i = 0; i < users_len; i++) {
cJSON *user_object = cJSON_CreateObject();
cJSON_AddItemToArray(users_array, user_object);
cJSON_AddStringToObject(user_object, "username", users[i].username);
cJSON_AddStringToObject(user_object, "email", users[i].email);
}
cJSON_Delete(users_array);
return JSON(res, 200, users_array);
}
int main(void) {
Server server = NewServer(8080);
ServerGet(&server, "/users", &GetUsers);
ServerListen(&server);
return 0;
}- Parse the HTTP request
- Respond to the HTTP request with some basic text
- Basic routing
- Read the headers
- Parse the HTTP
- Status
- Method
- Headers
- Body
- Abstract parsing
- Abstract getting header key
- HTTP Response creation
- string/html
- JSON - with some lib
- io_uring
- Event loop
- Async socket handling
- Add coroutines
- Async file reading, and file writing
- Async
optionalbody parsing
- Optimize io_uring, bulk complete tasks and mark as seen
- Proper error handling
- Error logging, perror, strerror and assertions
- Assert on invalid library user errors
- Paths should just be a vector
- Cleanup API and add missing basic stuff
- Properly free all resources
- Find errors with fuzzing
- Stress Test
- Graph based routing