| 10 |
**Dependencies:** Database class, Session classes, Utility classes (##Ut##), Diagnostics class (##Diag##) |
| 11 |
|
| 12 |
---- |
| 13 |
|
| 14 |
=== Class Properties === |
| 15 |
|
| 16 |
====Public Properties==== |
| 17 |
|
| 18 |
#| |
| 19 |
*| Property | Type | Description |* |
| 20 |
|| ##$tls_session## | bool | Indicates if the current session uses HTTPS/TLS encryption || |
| 21 |
|| ##$request_uri## | string | Normalized REQUEST_URI (e.g., 'PageOfNoReturn/show?a=1') || |
| 22 |
|| ##$ip## | string | Client's real IP address (accounts for proxies) || |
| 23 |
|| ##$sess## | Session | Reference to the Session object || |
| 24 |
|| ##$method## | string | Current HTTP method/request type || |
| 25 |
|# |
| 26 |
|
| 27 |
====Private Properties==== |
| 28 |
|
| 29 |
#| |
| 30 |
*| Property | Type | Description |* |
| 31 |
|| ##$db## | object | Database connection reference || |
| 32 |
|| ##$tls_mark## | string | Cookie name for TLS session marking || |
| 33 |
|| ##$page## | string | Current page name being processed || |
| 34 |
|| ##$hash## | string | SHA1 hash of the page name || |
| 35 |
|| ##$query## | string | Encoded query string || |
| 36 |
|| ##$lang## | string | Current language code || |
| 37 |
|| ##$file## | string | Cache file path || |
| 38 |
|| ##$caching## | int | Flag indicating if page should be cached (0 or 1) || |
| 39 |
|# |
| 40 |
|
| 41 |
---- |
| 42 |
=== Constructor === |
| 43 |
|
| 44 |
%%php |
| 415 |
- `$path` - ##$path## (string) - File path (or HTTP_XXX constant for error pages) |
| 416 |
- `$filename` - ##$filename## (string, optional) - Custom download filename |
| 417 |
- `$age` - ##$age## (int, optional) - Cache age in days |
| 418 |
|
| 419 |
**Features:** |
| 420 |
- HTTP range request support (partial file downloads) |
| 421 |
- ETag and Last-Modified conditional requests |
| 422 |
- Proper MIME type detection |
| 423 |
- Content-Security-Policy for special file types |
| 424 |
- Streaming for large files |
| 425 |
- GZip compression for text files |
| 530 |
#| |
| 531 |
*| Setting | Type | Purpose |* |
| 532 |
|| ##base_url## | string | Wiki's base URL || |
| 533 |
|| ##tls## | bool | Enable HTTPS enforcement || |
| 534 |
|| ##cache## | bool | Enable page caching || |
| 535 |
|| ##cache_ttl## | int | Cache lifetime in seconds || |
| 536 |
|| ##session_store## | int | 1=File, 0=Database || |
| 537 |
|| ##system_seed_hash## | string | Session encryption seed || |
| 538 |
|| ##cookie_prefix## | string | Session cookie prefix || |
| 539 |
|| ##cookie_path## | string | Cookie path || |
| 540 |
|| ##allow_persistent_cookie## | bool | Allow persistent login || |
| 541 |
|| ##session_length## | int | Session lifetime in seconds || |
| 542 |
|| ##reverse_proxy_addresses## | string | Comma/space-separated proxy IPs || |
| 543 |
|| ##reverse_proxy_header## | string | Custom X-Forwarded header || |
| 544 |
|| ##language## | string | Default language code || |
| 545 |
|| ##multilanguage## | bool | Enable language negotiation || |
| 546 |
|| ##allowed_languages## | string | Comma/space-separated allowed langs || |
| 547 |
|| ##enable_security_headers## | bool | Send security headers || |
| 548 |
|| ##csp## | int | CSP setting (0/1/2) || |
| 549 |
|| ##permissions_policy## | int | Permissions-Policy setting (0/1/2) || |
| 550 |
|| ##referrer_policy## | int | Referrer-Policy setting (0-8) || |
| 551 |
|# |
| 552 |
|
| 553 |
---- |
| 554 |
|
| 555 |
===Constants Used=== |
| 556 |
|
| 557 |
#| |
| 558 |
*| Constant | Type | Purpose |* |
| 559 |
|| ##IN_WACKO## | bool | Security check (exit if not defined) || |
| 560 |
|| ##CHMOD_SAFE## | int | File permissions for cache files || |
| 561 |
|| ##CHMOD_FILE## | int | File permissions for config cache || |
| 562 |
|| ##CACHE_PAGE_DIR## | string | Page cache directory || |
| 563 |
|| ##CACHE_SESSION_DIR## | string | Session cache directory || |
| 564 |
|| ##CACHE_CONFIG_DIR## | string | Config cache directory || |
| 565 |
|| ##CONFIG_DIR## | string | Configuration directory || |
| 566 |
|| ##LANG_DIR## | string | Language files directory || |
| 567 |
|| ##DAYSECS## | int | Seconds in a day (86400) || |
| 568 |
|| ##HTTP_404## | string | Path to 404 error page || |
| 569 |
|| ##HTTP_403## | string | Path to 403 error page || |
| 570 |
|# |
| 571 |
|
| 572 |
---- |
| 573 |
|
| 574 |
=== Workflow Examples === |
| 575 |
|
| 576 |
====Example 1: Handling a GET Request==== |
| 577 |
|
| 578 |
%%(hl php) |
| 625 |
```%% |
| 626 |
|
| 627 |
---- |
| 628 |
|
| 629 |
## Security Considerations=== Security Considerations === |
| 630 |
|
| 631 |
### 1. **IP Address Spoofing**==== 1. **IP Address Spoofing** ==== |
| 632 |
- Validates IPs against private ranges |
| 633 |
- Filters proxy-provided IPs appropriately |
| 634 |
- Configurable reverse proxy trust |
| 635 |
|
| 636 |
### 2. **Session Security**==== 2. **Session Security** ==== |
| 637 |
- Binds sessions to IP address |
| 638 |
- Binds sessions to TLS status |
| 639 |
- Supports both file and database storage |
| 640 |
- HttpOnly cookies by default |
| 641 |
|
| 642 |
### 3. **TLS Enforcement**==== 3. **TLS Enforcement** ==== |
| 643 |
- Automatic HTTPS upgrade when configured |
| 644 |
- Marks TLS sessions to prevent downgrade attacks |
| 645 |
- HSTS header support |
| 646 |
|
| 647 |
### 4. **Content Security**==== 4. **Content Security** ==== |
| 648 |
- CSP headers to prevent XSS |
| 649 |
- X-Frame-Options to prevent clickjacking |
| 650 |
- X-Content-Type-Options to prevent MIME sniffing |
| 651 |
- Referrer-Policy control |
| 652 |
- Permissions-Policy for browser features |
| 653 |
|
| 654 |
### 5. **File Serving**==== 5. **File Serving** ==== |
| 655 |
- Validates file existence and readability |
| 656 |
- Prevents directory traversal via `realpath()` - Prevents directory traversal via ##realpath()## |
| 657 |
- Rejects symbolic links |
| 658 |
- Special CSP for SVG and PDF files |
| 659 |
|
| 660 |
### 6. **Cache Security**==== 6. **Cache Security** ==== |
| 661 |
- Cached only for anonymous users |
| 662 |
- Disabled for sensitive operations (edit, watch) |
| 663 |
- Only GET requests cached |
| 664 |
|
| 665 |
---- |
| 666 |
|
| 667 |
## Performance Optimization=== Performance Optimization === |
| 668 |
|
| 669 |
### 1. **Page Caching**==== 1. **Page Caching** ==== |
| 670 |
- Stores full HTML output |
| 671 |
- TTL-based expiration |
| 672 |
- Language and method-aware caching |
| 673 |
- Conditional request support (304 Not Modified) |
| 674 |
|
| 675 |
### 2. **MIME Type Caching**==== 2. **MIME Type Caching** ==== |
| 676 |
- Loads MIME types once and caches |
| 677 |
- Regenerates only when config changes |
| 678 |
|
| 679 |
### 3. **Session Options**==== 3. **Session Options** ==== |
| 680 |
- File-based sessions for simple deployments |
| 681 |
- Database sessions for distributed systems |
| 682 |
|
| 683 |
### 4. **Compression**==== 4. **Compression** ==== |
| 684 |
- Manual gzip implementation |
| 685 |
- Proper Content-Length generation |
| 686 |
- Only compresses appropriate sizes |
| 687 |
|
| 688 |
---- |
| 689 |
|
| 690 |
## Debugging=== Debugging === |
| 700 |
%% |
| 701 |
|
| 702 |
---- |
| 703 |
|
| 704 |
=== Related Classes === |
| 705 |
- **Session Classes** (##SessionFileStore##, ##SessionDbalStore##) - Session management backends |
| 706 |
- **Database Class** - Configuration and cache metadata storage |
| 707 |
- **Ut Utility Class** - String/path utilities |
| 708 |
- **Diag Class** - Diagnostic logging |
| 709 |
|
| 710 |
---- |
| 711 |
|
| 712 |
=== Version History === |
| 713 |
- Supports PHP 8.0+ (uses match expressions, union types) |
| 714 |
- Follows RFC 9110 for HTTP header handling |
| 715 |
- Modern cookie security practices |
| 716 |
|
| 717 |
---- |
| 718 |
|
| 719 |
=== Conclusion === |
| 720 |
|
| 721 |
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: |
| 722 |
- Extending WackoWiki with custom request handlers |
| 723 |
- Implementing custom session logic |
| 724 |
- Adding new security policies |
| 725 |
- Optimizing cache strategies |
| 726 |
- Debugging HTTP-related issues |