Skip to content

r4hulrr/http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server (C++ / POSIX Sockets)

Lightweight HTTP/1.1 server built from scratch in C++ using a custom thread pool.

image

Demonstration of concurrent clients and gzip compression.

I built this to practice writing high-quality multithreaded C++ and to understand socket-level networking - how requests are parsed, how threads synchronize, and what really happens between recv() and send(). The focus was on clarity, ownership, and performance - not frameworks or abstractions.

The server runs on a simple thread-pool model: one thread accepts connections, workers pop Client objects from a blocking queue and handle them independently. Each client is fully RAII-managed and movable to ensure clean socket teardown and no descriptor leaks under load.

Key Details

  • Concurrency: Custom blocking WorkQueue + thread pool (std::thread, std::condition_variable)
  • Compression: GZIP with zlib, automatically used when Accept-Encoding: gzip is set
  • Routing: /echo/, /user-agent, and file GET/POST via /files/ (configurable via --directory)
  • Safety: Rejects unsafe filenames (../), no shared mutable state
  • Build: Standard CMake / Makefile, links against system zlib

Running

mkdir build && cd build
cmake .. && make
./http_server --directory ./public

Future Work

Next steps are to implement HTTP Keep-Alive for persistent connections and move toward an epoll-based I/O model to explore event-driven concurrency.

About

Lightweight HTTP/1.1 server built from scratch in C++ using a custom thread pool

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors