$ show HFQR/xitca-web
This is the xitca-web workspace, a high-performance, modular async web framework in Rust. It provides server and client capabilities for HTTP/1, HTTP/2, and HTTP/3, along with WebSocket, gRPC, TLS (rustls, OpenSSL, native-tls), static file serving, content compression (brotli, gzip, deflate, zstd), multipart form handling, and rate limiting. The framework is built on a core `Service`/`ReadyService` trait system that allows composable middleware pipelines, similar to Tower but with its own ergonomic design. It also includes an async PostgreSQL driver with full protocol support, connection pooling, and io_uring integration. The architecture is organized into many focused crates (`xitca-http`, `xitca-server`, `xitca-client`, `xitca-service`, `xitca-router`, `xitca-io`, etc.), all within a single workspace. Key strengths include zero-copy buffer management, custom protocol implementations (HPACK, QPACK) with security mitigation for known HTTP/2 vulnerabilities, and a flexible handler extraction system. The codebase demonstrates high craftsmanship with extensive testing, benchmarks, and security-conscious design, though it contains some unsafe code and has a large feature flag surface.
The LLM identified 5 files worth highlighting for reuse:
Implements the Generic Cell Rate Algorithm (GCRA) for rate limiting. This is a self-contained, pure Rust implementation that can be extracted and used in any project needing precise token-bucket-style rate limiting. It demonstrates careful handling of time, quota configuration, and state management, with property-based tests ensuring correctness. The component is well-encapsulated, depends only on standard types, and provides a clean `Gcra` struct that can be plugged into any middleware or service.
A radix tree implementation for URL routing, forked from `matchit` with significant enhancements. It supports parameterized routes, catch-all segments, and backtracking for conflict resolution. The tree handles insertion, removal, matching, and iteration with careful normalization of route parameters. It is a standalone module with no internal dependencies beyond standard library, and its test suite covers many edge cases (wildcard suffixes, trailing slashes, overlapping patterns). This could be extracted as a general-purpose URL router for any Rust web framework.
Implements a `SyncBridge` that adapts synchronous TLS streams (OpenSSL, native-tls) to async I/O using `AsyncBufRead`/`AsyncBufWrite` traits. It uses a `RefCell`-based design to bridge the blocking nature of TLS handshake and I/O with completion-based async runtimes. This is a non-trivial pattern that allows reusing existing blocking TLS libraries in an async context without full async-native implementations. The module is self-contained within the `tls` crate and demonstrates careful handling of phantom lifetime parameters and dual-role read/write ownership.
Implements the `FromRequest` and `Responder` traits that enable type-safe request extraction and response generation. It uses a tuple-based macro system to support handler functions with up to 9 extractor arguments. The pattern is exclusively trait-based and could be extracted as a generic request processing library. It demonstrates advanced use of sealed traits, blanket implementations, and careful handling of body consumption and response creation. This is a foundational pattern that many web frameworks replicate, but this implementation is particularly clean and composable.
Provides a `Coder` enumeration that wraps different compression algorithms (brotli, gzip, deflate, zstd) behind a unified `Code` trait. It handles streaming encode/decode with trailer propagation, content-encoding negotiation, and non-content-aware streaming. The module is feature-gated per algorithm and can be extracted as a standalone compression middleware crate. The design demonstrates clean trait usage and proper handling of encoding state machine transitions, including error recovery and flush semantics.