This project implements a simple HTTP server in C. It handles various HTTP methods, processes requests, and generates responses based on client requests. The server is built using low-level socket programming and custom HTTP request/response handling.
- HTTP Request Parsing: Support for multiple HTTP methods including GET, POST, PUT, DELETE, and more.
- Request Dispatching: Dispatches requests based on URI and method.
- Non-Blocking I/O: Uses non-blocking sockets to handle multiple clients concurrently.
- Customizable Response: Dynamically builds and sends HTTP responses based on the request and server logic.
- Modular Design: Organized into multiple files for handling sockets, HTTP requests, responses, and server operations.
http_handler.c/http_handler.h: Manages the request handling and dispatch logic.my_socket.c/my_socket.h: Contains functions for setting up and managing server sockets.request.c/request.h: Responsible for parsing HTTP requests and managing request headers and body.response.c/response.h: Handles building and formatting HTTP responses, including headers and body.server.c: Main entry point of the server, manages client connections and the server loop.my_http.h: Contains common HTTP-related constants and definitions used across the project.
- Clone the repository:
git clone [repository URL] - Compile the project:
Navigate to the project directory and run
make. - Run the server:
Execute
./serverand handle incoming HTTP requests on the specified port.
Start the server and visit http://localhost:4221/ to interact with it. It handles routes like /, /echo/, and /user-agent and responds with the appropriate content.
- Compiler: GCC (or another C compiler)
- Environment: POSIX-compliant system (Linux/macOS)
This project serves as a base for further extensions like adding more HTTP methods, handling file uploads, or implementing a full-fledged web server.