A lightweight, multi-threaded HTTP server written in C. This project implements a core HTTP/1.1 engine from scratch, featuring a custom request parser, response builder, and a flexible routing system.
- Multi-threaded Architecture: Uses
pthreadsto handle multiple simultaneous client connections without blocking. - Static File Serving: Automatically serves HTML files from a dedicated
public/directory. - Custom Request Parser: Efficiently parses HTTP methods, paths, and headers using a zero-copy approach.
- Dynamic Routing: Easily map URIs to C handler functions.
- Zero-Dependency: Built using only standard C libraries and Linux socket APIs.
HTTP-Server/
├── include/
│ ├── request.h # HTTP Request structures and parser prototypes
│ ├── response.h # HTTP Response structures and builder prototypes
│ ├── router.h # Routing engine and handler types
│ └── server.h # Socket initialization and server loop
├── src/
│ ├── main.c # Entry point and route registration
│ ├── request.c # Request parsing logic
│ ├── response.c # Response rendering logic
│ ├── router.c # Route matching implementation
│ └── server.c # Socket setup and multi-threaded connection handling
├── public/ # Static assets (HTML, etc.)
├── Makefile # Build system (linked with -pthread)
├── DEVELOPMENT_PLAN.md # Roadmap and progress tracking
└── README.md # This file
- GCC compiler
- Make
- POSIX-compliant OS (Linux/macOS)
To compile the project, run:
makeTo start the server on port 8080:
make runOnce running, you can access the server at http://localhost:8080.
Since the server listens on INADDR_ANY, it is accessible from any device on your Local Area Network (LAN).
- Find your Local IP: Run
hostname -Iin your terminal. - Connect: On your phone or another laptop connected to the same Wi-Fi, go to:
http://[YOUR_IP]:8080
- Fork the repository
- Create a new branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -m "Add new feature" - Push to your branch:
git push origin feature/my-feature - Open a Pull Request