A lightweight HTTP server implemented in C that serves static files (HTML and images) with proper MIME type detection.
- Serves static HTML files from
/app
directory - Serves images from
/img
directory - Supports multiple file types (HTML, PNG, JPG, GIF)
- Proper MIME type detection
- Basic error handling
- Fork-based request handling for concurrent connections
- GCC compiler
- Make build system
- UNIX-like operating system (Linux, macOS)
- Clone the repository:
git clone <repository-url>
cd http-server
- Build the server:
make
This will:
- Create necessary directories (
app
andimg
) - Compile the server
- Start the server:
./httpd <port>
Example:
./httpd 8080
- Directory Structure:
.
├── app/ # Place HTML files here
│ └── *.html
├── img/ # Place images here
│ └── *.png, *.jpg, *.gif
└── httpserver # Server executable
- Accessing Files:
- HTML files:
http://localhost:8080/app/filename.html
- Images:
http://localhost:8080/img/image.png
- HTML files (
.html
,.htm
) - Images:
- PNG (
.png
) - JPEG (
.jpg
,.jpeg
) - GIF (
.gif
)
- PNG (
make
: Build the servermake clean
: Clean build filesmake run
: Run server on port 8080make test
: Run basic server testmake install
: Install to system (requires sudo)
- HTML Files:
cp your_file.html app/
- Images:
cp your_image.png img/
Make sure files have proper permissions:
chmod 644 app/* img/*
The server provides basic error responses:
- 404 for files not found
- 200 for successful requests
- Basic error messages for server issues
- Server runs on localhost (127.0.0.1) by default
- No directory traversal protection implemented yet
- Limited to static file serving
- No SSL/TLS support
- Maximum URL length: 128 bytes
- Maximum request method length: 8 bytes
- Buffer size for file reading: 512 bytes
- No support for query parameters
- No caching implementation
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
github.com/omniflare
- Built with standard C libraries
- Inspired by basic HTTP protocol specifications
- Inspired by Foundations of Network Technology By Dr. Jonas Birch