Skip to content

noecrn/HTTPd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HTTPd

HTTPd is a lightweight HTTP/1.1 server daemon implemented in C. It strictly follows RFC 9110 and RFC 9112 standards to handle HTTP requests, manage connections, and serve static files efficiently .

🚀 Features

Core Capabilities

  • HTTP/1.1 Compliance: Implements GET and HEAD methods .
  • Daemon Mode: Runs as a background service with PID management.
  • Configuration: Parses a custom INI-style configuration file for global settings and VHosts.
  • Virtual Hosting: Supports IP-based and Name-based virtual hosts.
  • Logging: Access logs for requests and responses.

Technical Details

  • Architecture: Modular design separating Server, HTTP parsing, Daemon logic, and Configuration.
  • Network: Uses TCP/IPv4 sockets.
  • Graceful Shutdown: Handles SIGINT for clean termination of sockets and memory.

🛠️ Build & Usage

Compilation

The project follows strict C99 standards (-std=c99 -pedantic -Werror -Wall -Wextra -Wvla). To build the httpd executable:

make

Usage

./httpd [--daemon (start|stop|restart)] [--option value]

Common Options:

  • --pid_file <path>: Path to the PID file (Mandatory).
  • --port <number>: Server port.
  • --ip <address>: Server IP address.
  • --root_dir <path>: Root directory for serving files.

Configuration

The server can be launched using a configuration file and the helper script:

./config_reader.sh --path-bin ./httpd --path-config config.txt --daemon start

Example Config (config.txt):

[global]
log_file = server.log
log = true
pid_file = /tmp/httpd.pid

[[vhosts]]
server_name = myserver
port = 8080
ip = 127.0.0.1
root_dir = ./www
default_file = index.html

⚠️ Constraints & Compliance

  • Memory Management: Zero leaks allowed.
  • Error Handling: Returns correct HTTP status codes (200, 400, 403, 404, 405, 505) .
  • Security: Handles null bytes and malformed requests safely.

About

A compliant HTTP/1.1 server daemon written in C. Features persistent connections, virtual host configuration, and daemon management signals, implementing core RFC 9112 specifications.

Topics

Resources

Stars

Watchers

Forks

Contributors