Skip to content

7etsuo/http-server

Repository files navigation

Logo

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:

X Profile   Discord Server


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.


About

HTTP Server in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published