__ __ ______ ______ ______ __ __ ______
/\ \/ / /\ __ \ /\__ _\ /\ __ \ /\ "-.\ \ /\ __ \
\ \ _"-. \ \ __ \ \/_/\ \/ \ \ __ \ \ \ \-. \ \ \ __ \
\ \_\ \_\ \ \_\ \_\ \ \_\ \ \_\ \_\ \ \_\\"\_\ \ \_\ \_\
\/_/\/_/ \/_/\/_/ \/_/ \/_/\/_/ \/_/ \/_/ \/_/\/_/
A lightweight web server written in Rust, designed for serving static content with elegance
Features • Installation • Usage • Configuration • Contributing • License
Katana is a high-performance, minimalist web server built from scratch in Rust. While it started as a learning project, it's being developed with production-grade standards in mind. Perfect for serving static websites, file sharing, or as a development server.
Note: This project is currently in active development. While functional, it's not yet recommended for production use. Contributions and feedback are highly welcome!
- Static File Serving - Fast and efficient file delivery
- Directory Listing - Automatic, themed directory browsing with dark mode support
- Chunked Transfer - Optimized handling of large files (1KB chunks)
- Range Requests - Support for partial content delivery (HTTP 206)
- Flexible Configuration - Multiple configuration sources (CLI, env vars, config file)
- Multi-threading - Configurable worker threads for concurrent connections
- Cross-platform - Works on Windows, Linux, and macOS
- HTTP Methods: GET, HEAD, OPTIONS, TRACE
- HTTP Versions: HTTP/1.0, HTTP/1.1 support
- Content Types: Comprehensive MIME type detection
- Error Handling: Beautiful, themed error pages with dark mode
- Colorful Logging - Terminal output with ANSI color support
- Security - Protection against directory traversal, hidden files filtering
- Request Logging - Detailed request/response logging
- Docker Support - Ready-to-use containerization
Note: Before running any cargo command, make sure Rust and Cargo are already installed on your machine.
You can install both by using the official Rustup installer
cargo install --git https://github.com/ideatopia/katana# Build the image
docker build -t katana .
# Run the container
docker run -p 8080:8080 -v $(pwd)/public:/app/public katana# Clone the repository
git clone https://github.com/ideatopia/katana.git
cd katana
# Build in release mode
cargo build --release
# Binary will be in target/release/katana
./target/release/katana# Start with defaults (serves ./public on http://0.0.0.0:8080)
katana
# Specify custom options
katana --host 127.0.0.1 --port 3000 --document-root ./static --worker 8--host <ADDRESS>
Specifies the network address the server will bind to. Use 127.0.0.1 for local access only (recommended for development), or 0.0.0.0 to accept connections from any network interface.
- Default:
0.0.0.0on Unix-like systems (Linux, macOS) - Default:
127.0.0.1on Windows - Examples:
katana --host 127.0.0.1 # Local access only katana --host 0.0.0.0 # Accept from any interface katana --host 192.168.1.100 # Bind to specific IP
--port <NUMBER>
Sets the TCP port number the server will listen on. Choose ports above 1024 to avoid requiring administrator privileges.
- Default:
8080 - Range:
1-65535 - Examples:
katana --port 3000 # Common alternative port katana --port 8000 # Development server port katana --port 80 # Standard HTTP (requires admin rights)
--document-root <PATH>
Defines the root directory from which files will be served. Can be an absolute or relative path. The server will only serve files within this directory and its subdirectories.
- Default:
./public - Examples:
katana --document-root ./static # Relative path katana --document-root /var/www/html # Absolute path katana --document-root ~/Documents/site # Home directory path
--worker <NUMBER>
Controls the number of worker threads used to handle concurrent connections. More workers can improve performance under high load but will consume more system resources.
- Default:
4 - Recommended: Number of CPU cores or 2x CPU cores for I/O-bound workloads
- Examples:
katana --worker 2 # Low resource usage katana --worker 8 # High concurrency katana --worker 16 # Very high traffic
--log-level <LEVEL>
Sets the minimum severity level for log messages. Higher levels produce less output.
- Default:
INFO - Available levels:
DEBUG,INFO,WARN,ERROR - Level descriptions:
DEBUG: Detailed diagnostic information for developmentINFO: General informational messages about server operationsWARN: Warning messages for potentially problematic situationsERROR: Error messages for serious problems
- Examples:
katana --log-level DEBUG # Maximum verbosity katana --log-level INFO # Standard output katana --log-level WARN # Warnings and errors only katana --log-level ERROR # Errors only
You can combine multiple options to customize the server behavior:
# Development setup with detailed logging
katana --host 127.0.0.1 --port 3000 --document-root ./dist --log-level DEBUG
# Production-like setup with high concurrency
katana --host 0.0.0.0 --port 80 --document-root /var/www/html --worker 16 --log-level WARN
# File sharing server
katana --host 0.0.0.0 --port 8080 --document-root ~/Downloads --worker 4 --log-level INFOKatana supports multiple configuration sources with the following priority (highest to lowest):
- Command-line arguments (highest priority)
- Environment variables
- Configuration file (
.katana) - Default values (lowest priority)
Create a .katana file in your project root:
[katana]
# Server host (use "127.0.0.1" for local access only)
host = "127.0.0.1"
# Port number to run the server on
port = 8080
# Directory to serve static files from
document_root = "public"
# Number of worker threads for handling requests
worker = 4
# Logging level: DEBUG, INFO, WARN, ERROR
log_level = "INFO"export KATANA_HOST=0.0.0.0
export KATANA_PORT=8080
export KATANA_DOCUMENT_ROOT=public
export KATANA_WORKER=4
export KATANA_LOG_LEVEL=INFOWhen using Docker, you can configure via environment variables:
docker run -p 8080:8080 \
-e KATANA_HOST=0.0.0.0 \
-e KATANA_PORT=8080 \
-e KATANA_DOCUMENT_ROOT=public \
-e KATANA_WORKER=4 \
-e KATANA_LOG_LEVEL=info \
-v $(pwd)/public:/app/public \
katana# Navigate to your website directory
cd /var/www/html/
# Start the server
katana --port 8000 --document-root .or directly specify the path:
katana --port 8000 --document-root /var/www/html/# Share files from a specific directory
katana --document-root ~/Downloads --port 8080 --host 0.0.0.0Based on your CPU cores, you can adjust the worker count for better performance:
# Optimize for concurrent connections
katana --worker 16 --port 80 --document-root /var/www/htmlkatana/
├── src/
│ ├── core/
│ │ ├── config/ # Configuration management
│ │ ├── server/ # HTTP server implementation
│ │ ├── resources/ # Templates and static resources
│ │ └── utils/ # Utility functions (logger, colorful output, etc.)
│ ├── lib.rs # Library entry point
│ └── main.rs # Binary entry point
├── templates/ # HTML templates (error, directory listing, banner)
├── tests/ # Unit and integration tests
├── .katana.example # Example configuration file
├── Dockerfile # Docker configuration
└── Cargo.toml # Rust dependencies
- Config System: Multi-source configuration with priority handling
- HTTP Parser: Custom HTTP/1.x request parser
- File Handler: Efficient file serving with chunked transfer and range support
- Template Engine: Simple placeholder-based template system
- Logger: Colorful, level-based logging with timestamp formatting
- Directory Traversal Protection: Prevents access to files outside the document root
- Hidden Files Filtering: Automatically blocks access to files starting with
.(except.well-known) - Safe Defaults: Localhost binding on Windows by default
- No Code Execution: Serves only static files, no server-side scripting
Important: This server is designed for serving static content only. Do not use it to serve sensitive data without additional security measures (HTTPS, authentication, etc.)
We welcome contributions! Here's how you can help:
- Report Bugs: Open an issue with detailed reproduction steps
- Suggest Features: Share your ideas for improvements
- Improve Documentation: Help make the docs clearer
- Submit Pull Requests: Fix bugs or add features
# Clone the repository
git clone https://github.com/ideatopia/katana.git
cd katana
# Create a new branch
git checkout -b feature/your-feature-name
# Make your changes and test
cargo build
cargo test
# Commit with clear messages
git commit -m "feat(): add your feature description"
# Push and create a pull request
git push origin feature/your-feature-name- Follow Rust's official style guidelines
- Run
cargo fmtbefore committing - Ensure
cargo clippypasses without warnings - Add tests for new features
- Update documentation as needed
- Multi-threading support
- Range request support (HTTP 206)
- Chunked transfer encoding
- Colorful terminal output (ANSI colors)
- Configuration file support (.katana)
- Environment variables support
- Directory traversal protection
- Hidden files filtering
- Logging system with levels
- HTTP Methods (GET, HEAD, OPTIONS, TRACE)
- Port availability check
- Help command support
- HTTPS/TLS support
- HTTP/2 support
- Compression (gzip, brotli)
- Custom error pages
- Access control (basic auth)
- Request rate limiting
- WebSocket support
- CGI/FastCGI support
- Plugin system
This project is licensed under the MIT License. See the LICENSE file for details.
Judicaël AHYI (@ludndev)
- GitHub: @ludndev
- Project: ideatopia/katana
- Built with Rust
- Special thanks to @tobihans for his invaluable feedbacks and support
- Thanks to the tech communities (@PythonBenin and @JsBenin) for their encouragement
- Thanks to all contributors and users!
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Star this repository if you find it useful!
Made with ❤️ and Rust