Servlin
A modular HTTP server library in Rust.
Features
forbid(unsafe_code)
- Threaded request handlers:
FnOnce(Request) -> Response + 'static + Clone + Send + Sync
- Uses async code internally for excellent performance under load
- JSON
- Server-Sent Events (SSE)
- Saves large request bodies to temp files
- Sends 100-Continue
- Limits number of threads and connections
- Modular: roll your own logging, write custom versions of internal methods, etc.
- No macros or complicated type params
- Good test coverage (63%)
Limitations
- New, not proven in production.
- To do:
- Request timeouts
chunked
transfer-encoding for request bodies- gzip
- brotli
- TLS
- automatically getting TLS certs via ACME
- Drop idle connections when approaching connection limit.
- Denial-of-Service mitigation: source throttling, minimum throughput
- Complete functional test suite
- Missing load tests
- Disk space usage limits
Examples
Complete examples: examples/
.
Simple example:
use Deserialize;
use json;
use ;
use ;
use Arc;
use TempDir;
let state = new;
let request_handler = move |req: Request| ;
let cache_dir = new.unwrap;
start_timer_thread;
let executor = new.unwrap;
# let permit = new;
# let server_permit = permit.new_sub;
# spawn;
executor.block_on.unwrap;
Cargo Geiger Safety Report
Alternatives
See rust-webserver-comparison.md.
Changelog
- v0.1.0 - Renamed library to Servlin.
TO DO
- Fix limitations above
- Support HEAD responses that have Content-Length set and no body.
- Update
rust-webserver-comparison.md
- Add missing data
- Add other servers from https://www.arewewebyet.org/topics/frameworks/
- Rearrange
- Generate geiger reports for each web server