httprs is a lightweight HTTP server written in Rust that demonstrates a Prefork Multi‑Process Model similar to the classic Apache httpd MPM Prefork.
It spawns a configurable number of worker processes that listen on a single TCP port and accept connections concurrently.
- Prefork: Spawns multiple worker processes at start‑up, each with its own event loop.
- Extensible Architecture:
Workertrait lets you plug in different worker types (TCP, UDP, TLS, etc.).Processtrait allows you to implement any protocol (HTTP, Echo, WebSocket, etc.).Handlertrait for routing HTTP requests to custom logic.
httprs/
├── src/
│ ├── args.rs # CLI arguments
│ ├── main.rs # Application entry point
│ ├── server/
│ │ └── mod.rs # Server orchestration
│ ├── worker/
│ │ ├── error.rs # Worker errors
│ │ ├── group.rs # WorkerGroup abstraction
│ │ ├── helper.rs # Forking / cleanup utilities
│ │ ├── manager.rs # Manager that keeps child processes alive
│ │ ├── mod.rs # Public worker trait
│ │ └── tcp.rs # TCP worker implementation
│ ├── http/
│ │ ├── header.rs # Header utilities
│ │ ├── http.rs # `Http1` process implementation
│ │ ├── request.rs # `HttpRequest` type
│ │ ├── response.rs # `HttpResponse` type
│ │ ├── value.rs # HTTP enums & errors
│ │ └── mod.rs
│ └── process/
│ ├── echo.rs # Example Echo process
│ └── mod.rs
├── Cargo.toml
├── Cargo.lock
└── README.md
cargo build --release
Run
```sh
./target/release/httprs \
--host 127.0.0.1 \
--port 8080 \
--worker 4 \
--timeout-ms 2000 \
--max-header-size 8192This command starts a HTTP server listening on 127.0.0.1:8080 with 4 preforked worker processes and a 2‑second accept timeout.
- Custom Handler – Implement the
Handlertrait and pass it toHttp1::new(). - Custom Process – Implement the
Processtrait (e.g., a WebSocket server). - Worker Customization – Replace
TcpWorkerwith a UDP worker or add TLS support.
Run the test suite with:
cargo testTests cover:
- URL parsing (
http/http.rs) - Echo server logic (
process/echo.rs) - Worker manager integration (
worker/manager.rs)