A CGI Web Server which is inspired by tiny-httpd and enhanced with the third-party libraries, libev, http-parser, hashmap, log.c. It shows you how a web server works briefly.
- Parse HTTP request
- Support GET, POST method
- Support CGI
- A simple logger
1.Install libev and Python3.
sudo apt install -y libev-dev python3
2.Pull the source code.
git clone https://github.com/uncle-lv/cgi-http-server.git
3.Into the directory src
, and run make
to compile the code.
make
4、Run CGI Server (the argument port
is optional)
./server {port}
There are several urls for testing,
/index.html
、/login.html
and etc.You should have the execute permission of CGI scripts.
src
├── hashmap.c
├── hashmap.h
├── http_parser.c
├── http_parser.h
├── http_request.c
├── http_request.h
├── log.c
├── log.h
├── Makefile
├── server
└── server.c
If you want to read the source code, please focus on http_request.*
and server.c
. The other files are third-party libraries.
hashmap: Hashmap implementation in C.
http_parser: HTTP request/response parser for C.
log.c: A simple logging library implemented in C99.
Looking forward to Any issue or pull request from you.
Maybe implement the whole HTTP/1.0 and CGI/1.1 in the future.