1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
//! # Ignitia - A Blazing Fast Rust Web Framework 🔥
//!
//! **Ignitia** is a high-performance, production-ready web framework for Rust that ignites your web development
//! experience with exceptional speed, memory safety, and developer ergonomics. Built on modern async Rust with
//! Tokio and Hyper, Ignitia provides a complete toolkit for building scalable web applications, APIs, and real-time
//! services with full HTTP/1.1, HTTP/2, HTTPS, and WebSocket support.
//!
//! ## 🔥 Key Features
//!
//! ### Multi-Protocol Excellence
//!
//! - **HTTP/1.1 & HTTP/2**: Full support with automatic protocol negotiation via ALPN
//! - **HTTPS/TLS**: Production-ready TLS with certificate management and modern cipher suites
//! - **WebSocket**: Native WebSocket protocol with connection management and message routing
//! - **H2C Support**: HTTP/2 over cleartext connections for development and internal services
//!
//! ### Performance Optimized
//!
//! - **155K+ RPS Capable**: Optimized for extreme throughput with zero-cost abstractions
//! - **Sub-millisecond Latency**: Fast request processing with efficient routing and middleware
//! - **Connection Pooling**: Advanced connection management and resource optimization
//! - **Memory Efficient**: Smart buffer management and minimal heap allocations
//! - **Radix Tree Routing**: O(k) route lookup complexity where k is path length
//! - **Lock-Free Reads**: Atomic router swapping for zero-downtime updates
//!
//! ### Developer Experience
//!
//! - **Type-Safe Routing**: Compile-time route validation with automatic parameter extraction
//! - **Rich Extractors**: JSON, forms, headers, cookies, query params, and custom extractors
//! - **Composable Middleware**: Flexible middleware pipeline for cross-cutting concerns
//! - **Comprehensive Error Handling**: Structured error types with detailed diagnostics
//! - **Hot Reloading**: Runtime route updates without connection drops
//!
//! ### Production Features
//!
//! - **Advanced CORS**: Regex-based origin matching with fine-grained control
//! - **Security Headers**: Built-in security middleware with configurable policies
//! - **Rate Limiting**: Token bucket algorithm with distributed support
//! - **Observability**: Structured logging, metrics, and request tracing
//! - **Multipart Forms**: File upload support with streaming and size limits
//! - **WebSocket Rooms**: Built-in room system for broadcast messaging
//!
//! ## 🚀 Quick Start Guide
//!
//! Add Ignitia to your `Cargo.toml` with desired features:
//!
//! ```
//! [dependencies]
//! ignitia = { version = "0.2.4", features = ["tls", "websocket"] }
//! tokio = { version = "1.40", features = ["full"] }
//! serde = { version = "1.0", features = ["derive"] }
//! ```
//!
//! ### Simple HTTP Server
//!
//! ```
//! use ignitia::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let router = Router::new()
//! .get("/", || async {
//! Ok(Response::text("Hello, Ignitia! 🔥"))
//! })
//! .get("/health", || async {
//! Ok(Response::json(serde_json::json!({"status": "healthy"}))?)
//! })
//! .post("/echo", |body: String| async move {
//! Ok(Response::text(format!("Echo: {}", body)))
//! });
//!
//! let addr = "127.0.0.1:8080".parse()?;
//! Server::new(router, addr).ignitia().await
//! }
//! ```
//!
//! ### Advanced HTTP/2 Configuration
//!
//! ```
//! use ignitia::{Router, Server, ServerConfig, Http2Config};
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> ignitia::Result<()> {
//! let router = Router::new()
//! .get("/", || async { Ok(ignitia::Response::text("HTTP/2 Ready! 🚀")) });
//!
//! // Configure HTTP/2 with optimizations
//! let config = ServerConfig {
//! http1_enabled: true,
//! http2: Http2Config {
//! enabled: true,
//! enable_prior_knowledge: true, // H2C support
//! max_concurrent_streams: Some(1000),
//! initial_connection_window_size: Some(1024 * 1024), // 1MB
//! keep_alive_interval: Some(Duration::from_secs(60)),
//! adaptive_window: true,
//! ..Default::default()
//! },
//! auto_protocol_detection: true,
//! max_request_body_size: 16 * 1024 * 1024, // 16MB
//! ..Default::default()
//! };
//!
//! let addr = "127.0.0.1:8080".parse()?;
//! Server::with_config(router, addr, config).ignitia().await
//! }
//! ```
//!
//! ## 🔒 HTTPS and TLS Support
//!
//! Ignitia provides comprehensive TLS support with modern security standards:
//!
//! ### Basic HTTPS Setup
//!
//! ```
//! use ignitia::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let router = Router::new()
//! .get("/", || async { Ok(Response::text("Secure Hello! 🔒")) });
//!
//! let addr = "127.0.0.1:8443".parse()?;
//! Server::new(router, addr)
//! .enable_https("server.crt", "server.key")?
//! .ignitia()
//! .await
//! }
//! ```
//!
//! ### Advanced TLS Configuration
//!
//! ```
//! #[cfg(feature = "tls")]
//! use ignitia::{TlsConfig, TlsVersion};
//!
//! #[cfg(feature = "tls")]
//! let tls_config = TlsConfig::new("cert.pem", "key.pem")
//! .with_alpn_protocols(vec!["h2", "http/1.1"]) // HTTP/2 priority
//! .with_protocol_versions(&[TlsVersion::TlsV12, TlsVersion::TlsV13])
//! .with_cipher_suites(&["TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"])
//! .enable_client_cert_verification();
//!
//! #[cfg(feature = "tls")]
//! Server::new(router, addr)
//! .with_tls(tls_config)?
//! .ignitia()
//! .await
//! ```
//!
//! ## 🌐 Advanced CORS Configuration
//!
//! Comprehensive CORS support for secure cross-origin requests:
//!
//! ### Production CORS Setup
//!
//! ```
//! use ignitia::{CorsMiddleware, Method, Router, Response};
//!
//! # async fn example() -> ignitia::Result<()> {
//! let cors = CorsMiddleware::new()
//! .allowed_origins(&["https://myapp.com", "https://admin.myapp.com"])
//! .allowed_methods(&[Method::GET, Method::POST, Method::PUT, Method::DELETE])
//! .allowed_headers(&["Content-Type", "Authorization", "X-API-Key"])
//! .expose_headers(&["X-Total-Count", "X-Rate-Limit-Remaining"])
//! .allow_credentials()
//! .max_age(86400) // 24 hours
//! .build()?;
//!
//! let router = Router::new()
//! .middleware(cors)
//! .get("/api/users", || async { Ok(Response::json(vec!["user1", "user2"])?) });
//! # Ok(())
//! # }
//! ```
//!
//! ### Regex-Based Origin Matching
//!
//! ```
//! use ignitia::CorsMiddleware;
//!
//! # fn example() -> ignitia::Result<()> {
//! let cors = CorsMiddleware::new()
//! .allowed_origin_regex(r"https://.*\.myapp\.com") // All subdomains
//! .allowed_origin_regex(r"https://localhost:\d+") // Local development ports
//! .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## 📡 WebSocket Support
//!
//! Full-featured WebSocket implementation with HTTP/2 compatibility:
//!
//! ### Advanced WebSocket Server
//!
//! ```
//! #[cfg(feature = "websocket")]
//! use ignitia::websocket::{websocket_handler, Message, WebSocketConnection};
//! use std::sync::Arc;
//! use tokio::sync::Mutex;
//! use std::collections::HashMap;
//!
//! #[cfg(feature = "websocket")]
//! type ClientMap = Arc<Mutex<HashMap<String, WebSocketConnection>>>;
//!
//! #[cfg(feature = "websocket")]
//! let clients: ClientMap = Arc::new(Mutex::new(HashMap::new()));
//!
//! #[cfg(feature = "websocket")]
//! let router = Router::new()
//! // Simple echo WebSocket
//! .websocket("/ws/echo", websocket_handler(|mut ws: WebSocketConnection| async move {
//! while let Some(message) = ws.recv().await {
//! match message {
//! Message::Text(text) => {
//! ws.send_text(format!("Echo: {}", text)).await?;
//! }
//! Message::Binary(data) => {
//! ws.send_bytes(data).await?;
//! }
//! Message::Ping(data) => {
//! ws.send_pong(data).await?;
//! }
//! Message::Close(_) => break,
//! _ => {}
//! }
//! }
//! Ok(())
//! }));
//! ```
//!
//! ## 🏗️ Framework Architecture
//!
//! Ignitia's layered architecture supports multiple protocols and advanced features:
//!
//! ```
//! ┌─────────────────────────────────────────────────────────────────────────────┐
//! │ Application Layer │
//! │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
//! │ │ Routes │ │ Middleware │ │ CORS │ │ WebSocket │ │
//! │ │ & Handlers │ │ Pipeline │ │Configuration│ │ Handlers │ │
//! │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
//! ├─────────────────────────────────────────────────────────────────────────────┤
//! │ Ignitia Framework │
//! │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
//! │ │ Router │ │ Server │ │ TLS │ │ WebSocket │ │
//! │ │ Radix Tree │ │ HTTP/1.1+2 │ │ ALPN & Cert │ │ Connection Management │ │
//! │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
//! ├─────────────────────────────────────────────────────────────────────────────┤
//! │ Runtime Layer (Tokio) │
//! │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
//! │ │ HTTP │ │ TLS │ │ TCP │ │ Async I/O │ │
//! │ │ (Hyper) │ │ (Rustls) │ │ Listeners │ │ & Futures │ │
//! │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
//! └─────────────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## 🔧 Feature Configuration
//!
//! Ignitia uses Cargo features for optional functionality:
//!
//! ### Available Features
//!
//! - **`tls`**: Enables HTTPS/TLS support with certificate management and ALPN protocol negotiation
//! - **`websocket`**: Enables WebSocket protocol support with connection management and message routing
//! - **`self-signed`**: Enables self-signed certificate generation for development environments
//! - **`default`**: No additional features (HTTP/1.1 and HTTP/2 over cleartext only)
//!
//! ## 🎯 Performance Benchmarks
//!
//! Ignitia is optimized for exceptional performance:
//!
//! ### Throughput (Requests/Second)
//!
//! - **Simple JSON API**: 155,000+ RPS (Radix mode)
//! - **Static file serving**: 140,000+ RPS
//! - **WebSocket connections**: 25,000+ concurrent
//! - **HTTPS with TLS 1.3**: 110,000+ RPS
//!
//! ### Latency (99th percentile)
//!
//! - **HTTP/1.1**: < 0.8ms
//! - **HTTP/2**: < 1.0ms
//! - **HTTPS**: < 1.3ms
//! - **WebSocket message**: < 0.5ms
//!
//! ### Resource Usage
//!
//! - **Memory per connection**: ~2KB
//! - **CPU overhead**: < 3% at 100K RPS
//! - **Binary size**: ~4MB (with all features)
//!
//! ## 📚 Core Concepts
//!
//! ### Request/Response Lifecycle
//!
//! ```
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ Ignitia Request Pipeline │
//! └─────────────────────────────────────────────────────────────────┘
//!
//! 1. Connection Accept (TCP/TLS)
//! ├─ Protocol Detection (HTTP/1.1, HTTP/2, WebSocket)
//! ├─ TLS Handshake (if HTTPS)
//! └─ Connection Pooling
//!
//! 2. Request Parsing
//! ├─ Header Parsing and Validation
//! ├─ Body Streaming (with size limits)
//! └─ Protocol-specific Processing
//!
//! 3. Middleware Pipeline (Request Phase)
//! ├─ CORS Preflight Handling
//! ├─ Authentication/Authorization
//! ├─ Rate Limiting
//! ├─ Request ID Generation
//! └─ Custom middleware
//!
//! 4. Route Resolution
//! ├─ Path Matching (radix tree O(k) lookup)
//! ├─ Parameter Extraction
//! ├─ Handler Selection
//! └─ WebSocket Upgrade Detection
//!
//! 5. Handler Execution
//! ├─ Extractor Processing
//! ├─ Business Logic
//! └─ Response Generation
//!
//! 6. Middleware Pipeline (Response Phase)
//! ├─ Error Handling
//! ├─ Response Headers (Security, CORS)
//! ├─ Compression
//! └─ Logging
//!
//! 7. Response Transmission
//! ├─ Protocol-specific Formatting
//! ├─ Connection Management
//! └─ Metrics Collection
//! ```
//!
//! ### Routing Modes
//!
//! Ignitia supports two routing modes optimized for different use cases:
//!
//! #### Radix Mode (Default - Recommended)
//!
//! - **Performance**: O(k) lookup where k is path length
//! - **Best for**: Applications with 50+ routes
//! - **Features**: Compressed prefix tree, efficient parameter extraction
//! - **Memory**: Optimized for large route sets
//!
//! #### Base Mode
//!
//! - **Performance**: O(n) linear matching where n is route count
//! - **Best for**: Applications with < 50 routes
//! - **Features**: Simple regex-based matching
//! - **Memory**: Lower overhead for small apps
//!
//! ## 📖 Module Documentation
//!
//! ### Core Modules
//!
//! - [`cookie`]: HTTP cookie handling with secure defaults and session management
//! - [`error`]: Comprehensive error handling with structured error types and custom responses
//! - [`extension`]: Type-safe request/response extensions for sharing data between middleware
//! - [`handler`]: Request handlers, extractors, and handler trait implementations
//! - [`middleware`]: Middleware system including CORS, authentication, logging, and security
//! - [`multipart`]: Multipart form data parsing with file upload support
//! - [`request`]: HTTP request representation with efficient parsing and validation
//! - [`response`]: HTTP response building with content negotiation and streaming
//! - [`router`]: High-performance route matching with parameter extraction and middleware composition
//! - [`server`]: Multi-protocol server with HTTP/1.1, HTTP/2, TLS, and WebSocket support
//! - [`utils`]: Utility functions for common web development tasks
//!
//! ### Feature-Gated Modules
//!
//! - [`websocket`]: WebSocket protocol support with connection management (requires `websocket` feature)
//!
//! ## 🤝 Contributing
//!
//! We welcome contributions! Please see our [Contributing Guidelines](https://github.com/AarambhDevHub/ignitia/blob/main/CONTRIBUTING.md)
//! for information on:
//!
//! - Setting up the development environment
//! - Running tests and benchmarks
//! - Code style and documentation standards
//! - Submitting pull requests
//! - Reporting issues and feature requests
//!
//! ## 📄 License
//!
//! This project is licensed under the MIT License - see the [LICENSE](https://github.com/AarambhDevHub/ignitia/blob/main/LICENSE)
//! file for details.
//!
//! ## 🔗 Resources
//!
//! - **Repository**: <https://github.com/AarambhDevHub/ignitia>
//! - **Documentation**: <https://docs.rs/ignitia>
//! - **Examples**: <https://github.com/AarambhDevHub/ignitia/tree/main/examples>
//! - **Changelog**: <https://github.com/AarambhDevHub/ignitia/blob/main/doc/CHANGELOG.md>
//! - **Crates.io**: <https://crates.io/crates/ignitia>
// Enable documentation features for docs.rs
// Deny missing docs to ensure comprehensive documentation
// Enable additional documentation lint rules
use MiMalloc;
static GLOBAL: MiMalloc = MiMalloc;
// Core framework modules
// WebSocket support (feature-gated)
// Re-export cookie types for easy access
pub use ;
// Re-export error types and utilities
pub use ;
// Re-export extension system
pub use ;
// Re-export handler extractors with aliases to avoid naming conflicts
pub use ;
// Re-export handler types and utilities
pub use ;
// Re-export middleware types
pub use ;
// Re-export core request and response types
pub use Request;
pub use ;
// Re-export routing components
pub use ;
// Re-export server components
pub use ;
// Re-export multipart components
pub use ;
pub use ;
// Re-export WebSocket functionality when feature is enabled
pub use ;
// Re-export commonly used external types for convenience
/// Async trait support for defining async traits
pub use async_trait;
/// HTTP types from the `http` crate
pub use ;
// Version information
/// The current version of the Ignitia framework
pub const VERSION: &str = env!;
/// The name of the Ignitia framework
pub const NAME: &str = env!;
/// Framework information and build details
/// Prelude module for convenient imports
///
/// This module re-exports the most commonly used types and traits from Ignitia,
/// allowing applications to import everything needed with a single use statement.
///
/// # Usage
///
/// ```
/// use ignitia::prelude::*;
///
/// // Now you have access to Router, Server, Response, etc.
/// let router = Router::new();
/// let response = Response::text("Hello, World!");
/// ```
///
/// # Included Types
///
/// - **Core Types**: `Router`, `Server`, `Request`, `Response`, `Result`, `Error`
/// - **Configuration**: `ServerConfig`, `Http2Config`, `PerformanceConfig`
/// - **TLS Support**: `TlsConfig`, `TlsError`, `TlsVersion` (when `tls` feature is enabled)
/// - **Handlers**: `Handler`, `HandlerFn`, `IntoHandler`
/// - **Middleware**: `Middleware`, `CorsMiddleware`, `LoggerMiddleware`, `AuthMiddleware`
/// - **Extractors**: `Path`, `Query`, `Json`, `Headers`, `Body`, `Cookies`, `Uri`
/// - **HTTP Types**: `Method`, `StatusCode`, `HeaderMap`, `HeaderValue`
/// - **WebSocket**: `WebSocketConnection`, `Message`, `WebSocketHandler` (when `websocket` feature is enabled)
/// - **Utilities**: `async_trait` for defining async traits