This is a personal project I will be wroking on during the winter break, the goal is to learn more about linux, network, filesystem, etc..., and also learn c.
A small HTTP/1.1 server written in C from scratch using POSIX sockets.
It supports serving static files (HTML, CSS, Javascript, images) from www/ directory and is designed with a layered architecture see docs here: docs.pdf
.
Requires:
- Linux or macOS
- GCC or Clang
- POSIX environment
Compile everything with
gcc src/**/*.c -Iinclude -o my_server
By default the server listens on http://localhost:8080
The server is split into layers:
- OS
- Read/Write raw bytes
- TCP
- Accepts connections
- Buffer
- Manage partial reads-write safely
- HTTP parser
- Converts raw bytes into
http_request_t - Parse request line
- Converts raw bytes into
- Router
- Decides how to handle requestlayer
- Static file vs 404 (and later I hope, api)
- no HTTPS
- No chunked transfer encoding
no keep-alive (connection are closed after the response)- Single threaded, blocking I/O
HTTP headers parsingPOST request & body parsingkeep-alive supportepoll/ non-blocking I/O- thread pool
- Directory listing
- Basic api endpoints
- IPv6 support
- Security hardening (needed)