A Simple HTTP Server & Library written entirly from Scratch (Except for xxHash and Gzip), I used it as a gateway to learn few things, and think about particuler set of problems and decided to share that online.
u32 HttpServerMain()
{
Arena* arena = ArenaAlloc();
HttpServer server = HttpServerNew(arena, EndpointNew(Str8("0.0.0.0"), IPAddrKind::IPv4, 1337));
HttpHandle(server, Str8("/echo/"), [](const HttpRequest& request, HttpResponseWriter& writer) {
HttpSetStatus(writer, HttpStatusServerError);
HttpAddHeader(writer, Str8("WTF"), Str8("WITH YOU"));
HttpSend(writer, Str8("Tsunamii !!!!"));
});
printf("Listening on :1337\n");
if (!HttpListenAndServe(server))
{
fprintf(stderr, "[ERROR]: Failed to start server on port 1337\n");
return 1;
}
return 0;
}
int main(int argc, char* argv[])
{
ThreadStartParams params = { ThreadRoutine(HttpServerMain), nullptr };
OsHandle mainThread = OsCreateThread(ThreadMainEntry, ¶ms);
OsWaitForThread(mainThread, -1);
}