| 9 |
**Dependencies:** Database class, Session classes, Utility classes (##Ut##), Diagnostics class (##Diag##) |
| 10 |
|
| 11 |
---- |
| 12 |
|
| 13 |
=== Class Properties === |
| 14 |
|
| 15 |
====Public Properties==== |
| 16 |
|
| 17 |
#| |
| 18 |
*| Property | Type | Description |* |
| 19 |
|| ##$tls_session## | bool | Indicates if the current session uses HTTPS/TLS encryption || |
| 20 |
|| ##$request_uri## | string | Normalized REQUEST_URI (e.g., 'PageOfNoReturn/show?a=1') || |
| 21 |
|| ##$ip## | string | Client's real IP address (accounts for proxies) || |
| 22 |
|| ##$sess## | Session | Reference to the Session object || |
| 23 |
|| ##$method## | string | Current HTTP method/request type || |
| 24 |
|# |
| 25 |
|
| 26 |
====Private Properties==== |
| 27 |
|
| 28 |
#| |
| 29 |
*| Property | Type | Description |* |
| 30 |
|| ##$db## | object | Database connection reference || |
| 31 |
|| ##$tls_mark## | string | Cookie name for TLS session marking || |
| 32 |
|| ##$page## | string | Current page name being processed || |
| 33 |
|| ##$hash## | string | SHA1 hash of the page name || |
| 34 |
|| ##$query## | string | Encoded query string || |
| 35 |
|| ##$lang## | string | Current language code || |
| 36 |
|| ##$file## | string | Cache file path || |
| 37 |
|| ##$caching## | int | Flag indicating if page should be cached (0 or 1) || |
| 38 |
|# |
| 39 |
|
| 40 |
---- |
| 41 |
=== Constructor === |
| 42 |
|
| 43 |
%%php |
| 390 |
- `$path` - ##$path## (string) - File path (or HTTP_XXX constant for error pages) |
| 391 |
- `$filename` - ##$filename## (string, optional) - Custom download filename |
| 392 |
- `$age` - ##$age## (int, optional) - Cache age in days |
| 393 |
|
| 394 |
**Features:** |
| 395 |
- HTTP range request support (partial file downloads) |
| 396 |
- ETag and Last-Modified conditional requests |
| 397 |
- Proper MIME type detection |
| 398 |
- Content-Security-Policy for special file types |
| 399 |
- Streaming for large files |
| 400 |
- GZip compression for text files |
| 560 |
```%% |
| 561 |
|
| 562 |
---- |
| 563 |
|
| 564 |
## Security Considerations=== Security Considerations === |
| 565 |
|
| 566 |
### 1. **IP Address Spoofing**==== 1. **IP Address Spoofing** ==== |
| 567 |
- Validates IPs against private ranges |
| 568 |
- Filters proxy-provided IPs appropriately |
| 569 |
- Configurable reverse proxy trust |
| 570 |
|
| 571 |
### 2. **Session Security**==== 2. **Session Security** ==== |
| 572 |
- Binds sessions to IP address |
| 573 |
- Binds sessions to TLS status |
| 574 |
- Supports both file and database storage |
| 575 |
- HttpOnly cookies by default |
| 576 |
|
| 577 |
### 3. **TLS Enforcement**==== 3. **TLS Enforcement** ==== |
| 578 |
- Automatic HTTPS upgrade when configured |
| 579 |
- Marks TLS sessions to prevent downgrade attacks |
| 580 |
- HSTS header support |
| 581 |
|
| 582 |
### 4. **Content Security**==== 4. **Content Security** ==== |
| 583 |
- CSP headers to prevent XSS |
| 584 |
- X-Frame-Options to prevent clickjacking |
| 585 |
- X-Content-Type-Options to prevent MIME sniffing |
| 586 |
- Referrer-Policy control |
| 587 |
- Permissions-Policy for browser features |
| 588 |
|
| 589 |
### 5. **File Serving**==== 5. **File Serving** ==== |
| 590 |
- Validates file existence and readability |
| 591 |
- Prevents directory traversal via `realpath()` - Prevents directory traversal via ##realpath()## |
| 592 |
- Rejects symbolic links |
| 593 |
- Special CSP for SVG and PDF files |
| 594 |
|
| 595 |
### 6. **Cache Security**==== 6. **Cache Security** ==== |
| 596 |
- Cached only for anonymous users |
| 597 |
- Disabled for sensitive operations (edit, watch) |
| 598 |
- Only GET requests cached |
| 599 |
|
| 600 |
---- |
| 601 |
|
| 602 |
## Performance Optimization=== Performance Optimization === |
| 603 |
|
| 604 |
### 1. **Page Caching**==== 1. **Page Caching** ==== |
| 605 |
- Stores full HTML output |
| 606 |
- TTL-based expiration |
| 607 |
- Language and method-aware caching |
| 608 |
- Conditional request support (304 Not Modified) |
| 609 |
|
| 610 |
### 2. **MIME Type Caching**==== 2. **MIME Type Caching** ==== |
| 611 |
- Loads MIME types once and caches |
| 612 |
- Regenerates only when config changes |
| 613 |
|
| 614 |
### 3. **Session Options**==== 3. **Session Options** ==== |
| 615 |
- File-based sessions for simple deployments |
| 616 |
- Database sessions for distributed systems |
| 617 |
|
| 618 |
### 4. **Compression**==== 4. **Compression** ==== |
| 619 |
- Manual gzip implementation |
| 620 |
- Proper Content-Length generation |
| 621 |
- Only compresses appropriate sizes |
| 622 |
|
| 623 |
---- |
| 624 |
|
| 625 |
## Debugging=== Debugging === |
| 635 |
%% |
| 636 |
|
| 637 |
---- |
| 638 |
|
| 639 |
=== Related Classes === |
| 640 |
- **Session Classes** (##SessionFileStore##, ##SessionDbalStore##) - Session management backends |
| 641 |
- **Database Class** - Configuration and cache metadata storage |
| 642 |
- **Ut Utility Class** - String/path utilities |
| 643 |
- **Diag Class** - Diagnostic logging |
| 644 |
|
| 645 |
---- |
| 646 |
|
| 647 |
=== Version History === |
| 648 |
- Supports PHP 8.0+ (uses match expressions, union types) |
| 649 |
- Follows RFC 9110 for HTTP header handling |
| 650 |
- Modern cookie security practices |
| 651 |
|
| 652 |
---- |
| 653 |
|
| 654 |
=== Conclusion === |
| 655 |
|
| 656 |
The ##Http## class is the central request/response handler in WackoWiki, managing everything from session initialization to security headers to file serving. Understanding this class is essential for: |
| 657 |
- Extending WackoWiki with custom request handlers |
| 658 |
- Implementing custom session logic |
| 659 |
- Adding new security policies |
| 660 |
- Optimizing cache strategies |
| 661 |
- Debugging HTTP-related issues |