Skip to content

TomasBorquez/async-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

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;
}

TODOS

  • 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 optional body 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

Future

  • Graph based routing

Resources

About

An attempt of an HTTP implentation in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors