Here is an HTTP Server written in C. It support browsing through HTML files and also handlers. The browsing works with an abstract hashtable, key is the URL and value is a structure containing a file or a handler. The handler is a function pointer returning a dynamically generated HTML file.
It all began from a Youtube video shared by a friend (here). I wanted to do mine, and push it further :)
git clone https://github.com/HashDG/http-server.git
cd http-server
make
./http-server
Start Firefox and visit 127.0.0.1:1080
By default, HTML files have to be put in the http_ressources
folder, you can put all the files you need as long as it's indexed in the MIME database.
Furthermore, if you want to add handlers :
- write your handler in
session.c
as a function. Warning it has to follow this signaturechar * handler(char*,char**)
- add your handler in the
load_handlers
function following the example ofsimple_handler
In any folder, you can add CGI files. Make sure to make them .cgi
file. I tested only C compiled CGI, any compiled file which write on standard output should work.
NOTE: in testing CGI seems slow
- Arguments for handlers
- More methods for handlers
- CSS support
- Configuration file