This repository contains a multi-threaded HTTP server written in C. The server handles basic HTTP GET requests, serving static files from the file system.
- Multi-threaded: Each incoming client connection is handled by a separate thread, allowing for concurrent request processing.
- Dynamic Content Serving: Serves files with various MIME types based on the file extension.
- Graceful Error Handling: Returns appropriate HTTP status codes for unsupported methods and missing files.
To compile the server, use the following command:
gcc -o http_server http_server.c -lpthread -lregex
To start the HTTP server, run the compiled binary:
./http_server
By default, the server listens on port 8080 and serves files from the current directory.
./http_server
Visit http://localhost:8080/index.html in your web browser to access the default index.html file.
The server parses incoming HTTP requests and extracts the requested file name and extension. If no file is specified, the server defaults to serving index.html.
The server reads the requested file from disk and sends it as an HTTP response, along with the appropriate MIME type (e.g., text/html, image/jpeg). If the file is not found, the server responds with a 404 Not Found error.
Each client connection is handled by a new thread, allowing the server to handle multiple clients concurrently. The pthread library is used for thread creation and management.
The server detects the MIME type based on the file extension. Supported extensions include .html, .css, .jpeg, .jpg, and .png.
Add support for more HTTP methods (e.g., POST, PUT). Improve error handling and logging for better debugging and monitoring. Support serving files from different directories or virtual hosts.