A high-performance HTTP server written in Rust with support for CGI execution, file uploads, routing, session management, and dynamic configuration.
- Multi-server Support: Host multiple servers on different ports and addresses
- Advanced Routing: Flexible route configuration with methods, redirects, and default files
- CGI Execution: Execute server-side scripts (Python, shell, etc.) with configurable interpreters
- File Upload Handling: Built-in file upload support with configurable upload directories and size limits
- Session Management: Server-side session handling with configurable storage
- Custom Error Pages: Configure error pages for different HTTP status codes
- Auto-indexing: Optional directory listing
- Cookie & Session Support: Automatic session and cookie management
- Asynchronous I/O: Non-blocking networking using
miofor high concurrency - Static File Serving: Efficient serving of static content with path handling
- Request Validation: Configuration validation and client body size limits
├── src/
│ ├── bin/main.rs # Entry point
│ ├── server.rs # Main server loop and listener management
│ ├── router.rs # Request routing logic
│ ├── http/ # HTTP protocol handling
│ │ ├── http_connection.rs # Connection management
│ │ ├── request.rs # HTTP request parsing
│ │ └── response.rs # HTTP response building
│ ├── config/ # Configuration parsing and validation
│ ├── handlers/ # Request handlers
│ │ ├── get_handler.rs # GET request handling
│ │ ├── post_handler.rs # POST request handling
│ │ └── delete_handler.rs # DELETE request handling
│ ├── cgi.rs # CGI execution
│ ├── upload.rs # File upload handling
│ ├── utils/ # Utilities
│ │ ├── session.rs # Session management
│ │ ├── cookie.rs # Cookie parsing
│ │ └── set_cookie.rs # Cookie setting
│ └── lexer/ # YAML parsing support
├── parser/ # Custom YAML/config parser library
├── parser_derive/ # Macro for deriving parser traits
├── derive_yaml/ # Macro for YAML deserialization
├── proxy_log/ # Logging utilities
├── www/ # Static web files
│ ├── index.html # Main page
│ ├── upload.html # Upload interface
│ ├── api/ # API endpoints
│ ├── css/ # Stylesheets
│ └── errors/ # Custom error pages
├── cgis/ # CGI scripts
│ └── auth/ # Authentication scripts
├── tests/ # Integration tests
└── config.yaml # Server configuration
The server is configured via a YAML file (config.yaml). Key configuration options:
servers:
- host: "127.0.0.2" # Listen address
ports: [8080] # Listen ports
server_name: "localhost" # Server name
root: "www" # Root directory for static files
default_server: true # Default server for this address
client_max_body_size: 10000000000 # Max upload size in bytes
error_pages:
404: "./errors/404.html" # Custom error pages
405: "./errors/405.html"
routes: [...]routes:
- path: "/" # Route path
methods: ["GET","POST","DELETE"] # Allowed HTTP methods
root: "./www" # Document root for this route
default_file: "index.html" # Default file to serve
autoindex: true # Enable directory listing
upload_dir: "uploads" # Directory for file uploads
cgi_ext: ".py" # CGI script extension
cgi_path: "/usr/bin/python3.10" # CGI interpreter path
redirection: "https://google.com" # Redirect destination
redirect_code: 302 # HTTP redirect code- Rust 1.70+ (or 2024 edition)
- Python 3.10+ (for CGI scripts)
cargo build --releasecargo run --releaseThe server will read config.yaml and start listening on the configured addresses and ports.
Start a simple HTTP server on localhost:8080 serving files from www/:
servers:
- host: "127.0.0.1"
ports: [8080]
server_name: "localhost"
root: "www"
routes:
- path: "/"
methods: ["GET", "POST"]
default_file: "index.html"
autoindex: trueExecute Python scripts as CGI handlers:
routes:
- path: "/cgi-bin"
methods: ["GET", "POST"]
cgi_ext: ".py"
cgi_path: "/usr/bin/python3"
upload_dir: "uploads"Configure file upload endpoint:
routes:
- path: "/upload"
methods: ["POST", "GET"]
upload_dir: "uploads"
autoindex: falseManages TCP listeners, client connections, and the main event loop using non-blocking I/O.
Matches incoming requests to configured routes and determines how to handle them.
get_handler.rs: Serves static files, handles directory listingpost_handler.rs: Processes form data and file uploadsdelete_handler.rs: Handles DELETE requests
Spawns CGI processes with proper environment variables and handles bidirectional I/O.
YAML parsing and validation for server configuration.
Server-side session storage with automatic cleanup.
Run the test suite:
cargo testAvailable tests:
- Configuration parsing tests
- Server feature tests
- Chunked transfer encoding tests
- Validation tests
expand.sh: Expand macros for debuggingpush.zsh: Utility script (purpose varies)
MIT
aelmir | houtayb | muboutoub