https://github.com/7etsuo/http-server
HTTP Server in C
https://github.com/7etsuo/http-server
Last synced: 12 months ago
JSON representation
HTTP Server in C
- Host: GitHub
- URL: https://github.com/7etsuo/http-server
- Owner: 7etsuo
- Created: 2024-09-22T03:33:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-22T04:02:22.000Z (over 1 year ago)
- Last Synced: 2025-04-12T04:52:56.430Z (about 1 year ago)
- Language: C
- Size: 10.7 KB
- Stars: 32
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
HTTP Server in C
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.
---
Connect with me:
---
### Features:
- **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.
### Files Overview:
- `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.
### Usage:
1. **Clone the repository:**
`git clone [repository URL]`
2. **Compile the project:**
Navigate to the project directory and run `make`.
3. **Run the server:**
Execute `./server` and handle incoming HTTP requests on the specified port.
### Example:
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.
### Requirements:
- **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.
---