Skip to content

iamaliybi/rustrate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rustrate 🦀

A high-performance, multi-threaded asynchronous HTTP server engine written in Pure Rust.

Rustrate is a lightweight web server designed to handle multiple independent server instances simultaneously, each with its own configuration and lifecycle.


🚀 Key Architectural Features

  • Hybrid Concurrency Model:
    • Isolation: Each [server] block defined in the configuration runs on its own dedicated OS Thread.
    • Async Runtime: Inside each thread, a Tokio runtime handles thousands of concurrent requests using non-blocking I/O.
  • Protocol Support:
    • HTTP/1.0: Stable
    • HTTP/1.1: Stable (Keep-alive, Chunked Transfer, etc.)
    • HTTP/2.0: Work-in-Progress (Frame parsing and stream multiplexing)
  • Built-in SPA Support: Smart routing for Single Page Applications (automatically falls back to index.html).
  • Native TLS/SSL: Supports HTTPS using .pem certificates and keys.
  • Security & Constraints: Fine-grained control over max-header-size, max-body-size, and max-header-length.

⚙️ Configuration

Rustrate uses a server.conf file to manage multiple listeners. This allows you to run an HTTP and HTTPS server (or multiple sites) from a single binary:

[server]
port: 80
root: W:\path\to
index: index.html
spa: true
max-header-size: 2048
max-header-length: 25
max-body-size: 2097152

[server]
port: 443
root: W:\path\to
index: index.html
spa: true
max-header-size: 2048
max-header-length: 25
max-body-size: 2097152
tls-crt: W:\path\to\cert\localhost.pem
tls-key: W:\path\to\cert\localhost-key.pem

🛠 Getting Started

1. Prerequisites

Ensure you have the Rust toolchain (Edition 2021 or later) installed.

2. Configuration

The server looks for a server.conf file in the project root. Each block spawns a unique OS thread with its own Tokio runtime.

3. Build & Run

To compile and start the engine in production mode:

cargo run --release

🔬 Technical Deep Dive

Concurrency Model

Unlike traditional servers that use a single global runtime, Rustrate uses a hybrid approach:

  • Master Thread: Parses the server.conf and spawns worker threads.
  • Worker Threads: Each worker thread is dedicated to one port/server block and runs an independent tokio::runtime.
  • Request Handling: Within each runtime, requests are handled asynchronously.

SPA Support

When spa: true is set, any request that doesn't match a static file will be automatically served the index.html.


📜 License

Distributed under the MIT License.

About

A lightweight, high-performance HTTP server written in pure Rust from scratch. Supporting HTTP/1.0, 1.1, and a partial implementation of HTTP/2.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages