Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 5 additions & 51 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,8 @@

## Overview

`agent` is a lightweight HTTP server written in Rust that demonstrates a **Prefork Multi‑Process Model** similar to the classic Apache MPM Prefork.
It spawns a configurable number of worker processes that listen on a single TCP port and accept connections concurrently. The worker processes communicate with the parent via `fork` and `wait` system calls, handling each connection independently.

```

## Project Structure

```
server_rs/
├── src/
│ ├── args.rs # CLI arguments
│ ├── main.rs # Application entry point
│ ├── server/
│ │ └── mod.rs # Server and worker group orchestration
│ ├── worker/
│ │ ├── error.rs # Errors used by the worker manager
│ │ ├── 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
```
`httprs` is a lightweight HTTP server.
It aims to provide predictable HTTP server behavior without requiring external runtimes like tokio or async-std yet.

## Key Components

Expand Down Expand Up @@ -67,18 +34,13 @@ pub trait Worker {
}
```

### 5. `TcpWorker` (`worker/tcp.rs`)

* Listens on the shared `TcpListener` sockets.
* Accepts connections and hands them off to the `Process` implementation (`Http1` or `EchoProcess`).

### 6. `Http1` Process (`http/http.rs`)
### 5. `Http1` Process (`http/http.rs`)

* Implements the `Process` trait for handling HTTP/1.x requests.
* Parses request line, headers, and query parameters.
* Uses a `Handler` implementation to generate a response.

### 7. `Handler` Trait (`http/handler.rs`)
### 6. `Handler` Trait (`http/handler.rs`)

```rust
pub trait Handler {
Expand All @@ -88,7 +50,7 @@ pub trait Handler {

The `SimpleHandler` in `main.rs` is a minimal example that echoes request headers back.

### 8. `EchoProcess` (`process/echo.rs`)
### 7. `EchoProcess` (`process/echo.rs`)

* A simple echo server used in tests.
* Demonstrates how to implement a custom `Process`.
Expand Down Expand Up @@ -136,11 +98,3 @@ cargo test
* `colog` – Structured logging.
* `nix` – Low‑level Unix syscalls.
* `env_logger` – Log initialization.

## License

This project is licensed under the MIT license. Refer to `LICENSE` file in the repository root.

---

Feel free to customize the handler or worker logic to fit your specific use case.
43 changes: 2 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
# httprs

`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.

## Features

- **Prefork**: Spawns multiple worker processes at start‑up, each with its own event loop.
- **Extensible Architecture**:
- `Worker` trait lets you plug in different worker types (TCP, UDP, TLS, etc.).
- `Process` trait allows you to implement any protocol (HTTP, Echo, WebSocket, etc.).
- `Handler` trait for routing HTTP requests to custom logic.

## Project Layout

```
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
```
`httprs` is a lightweight HTTP server.
It aims to provide predictable HTTP server behavior without requiring external runtimes like tokio or async-std.

## Getting Started

Expand Down
Loading