Project: sunweb
Sunnickel | 04.10.2025
A lightweight, fast, and flexible HTTP/HTTPS web server written in Rust with domain routing, middleware support, and TLS capabilities.
Features
- HTTP/HTTPS Support: Built-in TLS/SSL support using rustls
- Domain-Based Routing: Multi-domain and subdomain routing capabilities
- Middleware System: Flexible middleware for request/response processing
- Static File Serving: Efficient static file serving with automatic MIME type detection
- Custom Route Handlers: Define custom logic for specific routes
- Cookie Management: Full cookie support with security attributes
- Colored Logging: Built-in colored console logging for better visibility
- Thread-Per-Connection: Handles each client connection in a separate thread
Installation
Add this to your Cargo.toml:
[] sunweb = "0.1.0"
Or install from GitHub:
[] sunweb = { git = "https://github.com/Sunnickel/SunWeb" }
Quick Start
use ;
use WEB_LOGGER;
Usage Examples
Basic HTTP Server
use ;
let config = new;
let server = new; server.start;
HTTPS Server with TLS
let config = new.add_cert.expect;
let server = new; server.start;
Custom Route Handlers
use ;
use Arc;
server.add_custom_route.unwrap;
Static File Serving
// Serve all files in the ./static folder under /static route
server.add_static_route.unwrap;
Working with Cookies
use ;
use Domain;
server.add_custom_route.unwrap;
Subdomain Routing
use Domain;
let api_domain = new;
server.add_subdomain_router;
// Add routes specifically for api.yourdomain.com
server.add_custom_route.unwrap;
API Overview
ServerConfig
Configure your web server:
new(host: [u8; 4], port: u16)- Create new configurationadd_cert(private_key: String, cert: String)- Enable HTTPSset_base_domain(domain: String)- Set the base domain
WebServer
Main server instance:
new(config: ServerConfig)- Create new serverstart()- Start listening for connectionsadd_route_file(route: &str, file: &str, domain: Option<&Domain>)- Add file routeadd_static_route(route: &str, folder: &str, domain: Option<&Domain>)- Add static folderadd_custom_route(route: &str, handler: Fn, domain: Option<&Domain>)- Add custom handleradd_subdomain_router(domain: &Domain)- Enable subdomain routing
Response
HTTP response handling:
new(content: Arc<String>, code: Option<ResponseCodes>, protocol: Option<String>)- Create responseadd_cookie(cookie: Cookie)- Add cookie to responseheaders.add_header(key: &str, value: &str)- Add custom header
Request
HTTP request information:
protocol: String- HTTP protocol versionmethod: String- HTTP method (GET, POST, etc.)route: String- Requested routevalues: HashMap<String, String>- Request headersremote_addr: String- Client IP addressget_cookies()- Get all cookiesget_cookie(key: &str)- Get specific cookie
Project Structure
RustWebservice/
├── src/
│ ├── webserver/
│ │ ├── client_handling/ # Client connection handling
│ │ ├── cookie/ # Cookie management
│ │ ├── files/ # Static file serving
│ │ ├── logger/ # Colored logging
│ │ ├── middleware/ # Middleware system
│ │ ├── requests/ # Request parsing
│ │ ├── responses/ # Response building
│ │ └── server_config/ # Server configuration
│ └── lib.rs
├── Cargo.toml
└── README.md
Dependencies
- chrono - Date and time handling
- log - Logging facade
- rustls - TLS/SSL implementation
- rustls-pki-types - PKI types for rustls
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Sunnickel
Links
AI Assistance
This project's documentation, including this README.md file, has been created with the assistance of AI.
Specifically, AI was used for:
- Documentation generation
- Content creation for this
README.md
All content has been reviewed and edited to ensure accuracy and clarity. While AI tools were utilized to accelerate the writing process, all information has been manually checked for correctness.