Difference between revisions for Users / Eo Ny / dev
| Version1 | Version2 | Differences |
|---|---|---|
| 1 |
|
|
| 2 |
|
|
| 3 | 1 | {{toc numerate=1}} |
| 2 | ||
| 4 | 3 | === Overview === |
| 5 | 4 | |
| 6 | 5 | The ##Http## class (##src/class/http.php##) is a core component of the WackoWiki system responsible for handling HTTP request/response processing, session management, caching, and security features. This class acts as a bridge between the web server and the wiki engine. |
| … | … | … |
| 41 | 40 | ---- |
| 42 | 41 | === Constructor === |
| 43 | 42 | |
| 44 |
%% |
|
| 43 | %%(hl php) | |
| 45 | 44 | public function __construct(&$db) |
| 46 | 45 | %% |
| 47 | 46 | |
| … | … | … |
| 59 | 58 | 6. Enforces TLS session upgrade if needed |
| 60 | 59 | |
| 61 | 60 | **Example:** |
| 62 |
%% |
|
| 61 | %%(hl php) | |
| 63 | 62 | $http = new Http($db); |
| 64 | 63 | %% |
| 65 | 64 | |
| … | … | … |
| 83 | 82 | - Recovers diagnostic logs from previous session |
| 84 | 83 | |
| 85 | 84 | **Example:** |
| 86 |
%% |
|
| 85 | %%(hl php) | |
| 87 | 86 | $http->session(0); // Normal session |
| 88 | 87 | $http->session(2); // Static file serving mode |
| 89 | 88 | %% |
| … | … | … |
| 106 | 105 | - ✅ Only cached for anonymous users (no logged-in users) |
| 107 | 106 | |
| 108 | 107 | **Example:** |
| 109 |
%% |
|
| 108 | %%(hl php) | |
| 110 | 109 | $http->check_cache('HomePage', 'show'); |
| 111 | 110 | %% |
| 112 | 111 | |
| 113 | 112 | ---- |
| 114 | 113 | |
| 115 |
===== |
|
| 114 | =====##store_cache(): void##===== | |
| 116 | 115 | Saves the generated page content to cache file. |
| 117 | 116 | |
| 118 | 117 | **Features:** |
| … | … | … |
| 122 | 121 | - Only executes if caching flag is set and user is anonymous |
| 123 | 122 | |
| 124 | 123 | **Example:** |
| 125 |
%% |
|
| 124 | %%(hl php) | |
| 126 | 125 | // Called at end of page rendering |
| 127 | 126 | $http->store_cache(); |
| 128 | 127 | %% |
| … | … | … |
| 145 | 144 | 4. Returns count of invalidated caches |
| 146 | 145 | |
| 147 | 146 | **Example:** |
| 148 |
%% |
|
| 147 | %%(hl php) | |
| 149 | 148 | $count = $http->invalidate_page('HomePage'); |
| 150 | 149 | echo "Invalidated $count cache entries"; |
| 151 | 150 | %% |
| … | … | … |
| 163 | 162 | - Called when TLS session is detected |
| 164 | 163 | |
| 165 | 164 | **Example:** |
| 166 |
%% |
|
| 165 | %%(hl php) | |
| 167 | 166 | $http->secure_base_url(); |
| 168 | 167 | // $db->base_url now uses https:// |
| 169 | 168 | %% |
| … | … | … |
| 182 | 181 | - Converts relative URLs using current server name |
| 183 | 182 | |
| 184 | 183 | **Example:** |
| 185 |
%% |
|
| 184 | %%(hl php) | |
| 186 | 185 | $http->ensure_tls('/secure/payment'); |
| 187 | 186 | %% |
| 188 | 187 | |
| … | … | … |
| 210 | 209 | - ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##) |
| 211 | 210 | |
| 212 | 211 | **Example:** |
| 213 |
%% |
|
| 212 | %%(hl php) | |
| 214 | 213 | $client_ip = $http->ip; // e.g., "203.0.113.42" |
| 215 | 214 | %% |
| 216 | 215 | |
| … | … | … |
| 254 | 253 | - ##2## - Custom policy (from ##csp_custom.conf##) |
| 255 | 254 | |
| 256 | 255 | **Example:** |
| 257 |
%% |
|
| 256 | %%(hl php) | |
| 258 | 257 | $http->http_security_headers(); |
| 259 | 258 | %% |
| 260 | 259 | |
| … | … | … |
| 274 | 273 | - Uses output buffering to work anywhere in page processing |
| 275 | 274 | |
| 276 | 275 | **Example:** |
| 277 |
%% |
|
| 276 | %%(hl php) | |
| 278 | 277 | $http->redirect('http://example.com/new-page', true); // 301 |
| 279 | 278 | $http->redirect('/wiki/HomePage'); // 302 |
| 280 | 279 | %% |
| … | … | … |
| 289 | 288 | - Ends script execution |
| 290 | 289 | |
| 291 | 290 | **Example:** |
| 292 |
%% |
|
| 291 | %%(hl php) | |
| 293 | 292 | $http->terminate(); |
| 294 | 293 | %% |
| 295 | 294 | |
| … | … | … |
| 299 | 298 | Sets HTTP response status code. |
| 300 | 299 | |
| 301 | 300 | **Supported Status Codes:** |
| 302 |
%% |
|
| 301 | %%(hl php) | |
| 303 | 302 | 200 => 'OK' |
| 304 | 303 | 206 => 'Partial Content' |
| 305 | 304 | 301 => 'Moved Permanently' |
| … | … | … |
| 319 | 318 | %% |
| 320 | 319 | |
| 321 | 320 | **Example:** |
| 322 |
%% |
|
| 321 | %%(hl php) | |
| 323 | 322 | $http->status(404); // Send 404 Not Found |
| 324 | 323 | %% |
| 325 | 324 | |
| … | … | … |
| 340 | 339 | - ##Cache-Control: no-store## |
| 341 | 340 | |
| 342 | 341 | **Example:** |
| 343 |
%% |
|
| 342 | %%(hl php) | |
| 344 | 343 | $http->no_cache(); // Client-side only |
| 345 | 344 | $http->no_cache(false); // Both client & server |
| 346 | 345 | %% |
| … | … | … |
| 354 | 353 | - ##Cache-Control: public## |
| 355 | 354 | |
| 356 | 355 | **Example:** |
| 357 |
%% |
|
| 356 | %%(hl php) | |
| 358 | 357 | $http->cache_promisc(); |
| 359 | 358 | %% |
| 360 | 359 | |
| … | … | … |
| 399 | 398 | - Associative array: ##['en' => 'en', 'de' => 'de', ...]## |
| 400 | 399 | |
| 401 | 400 | **Example:** |
| 402 |
%% |
|
| 401 | %%(hl php) | |
| 403 | 402 | $all_langs = $http->available_languages(false); |
| 404 | 403 | $allowed = $http->available_languages(true); |
| 405 | 404 | %% |
| … | … | … |
| 425 | 424 | - GZip compression for text files |
| 426 | 425 | |
| 427 | 426 | **Special Paths:** |
| 428 |
%% |
|
| 427 | %%(hl php) | |
| 429 | 428 | $http->sendfile(404); // Serves file defined by HTTP_404 constant |
| 430 | 429 | $http->sendfile(403); // Serves file defined by HTTP_403 constant |
| 431 | 430 | %% |
| 432 | 431 | |
| 433 | 432 | **Example:** |
| 434 |
%% |
|
| 433 | %%(hl php) | |
| 435 | 434 | $http->sendfile('uploads/document.pdf', 'my-document.pdf', 30); |
| 436 | 435 | %% |
| 437 | 436 | |
| … | … | … |
| 445 | 444 | - Default: ##'application/octet-stream'## |
| 446 | 445 | |
| 447 | 446 | **Example:** |
| 448 |
%% |
|
| 447 | %%(hl php) | |
| 449 | 448 | $mime = $http->mime_type('file.pdf'); // 'application/pdf' |
| 450 | 449 | %% |
| 451 | 450 | |
| … | … | … |
| 475 | 474 | - Headers not already sent |
| 476 | 475 | |
| 477 | 476 | **Example:** |
| 478 |
%% |
|
| 477 | %%(hl php) | |
| 479 | 478 | $http->gzip(); |
| 480 | 479 | %% |
| 481 | 480 | |
| … | … | … |
| 491 | 490 | - Converts encoding properly |
| 492 | 491 | |
| 493 | 492 | **Example:** |
| 494 |
%% |
|
| 493 | %%(hl php) | |
| 495 | 494 | $data = $http->parse_str('name=John&age=30'); |
| 496 | 495 | %% |
| 497 | 496 | |
| … | … | … |
| 597 | 596 | |
| 598 | 597 | ==== Example 2: Handling TLS/HTTPS Upgrade ==== |
| 599 | 598 | |
| 600 |
%% |
|
| 599 | %%(hl php) | |
| 601 | 600 | $http = new Http($db); // Constructor detects TLS requirement |
| 602 | 601 | // If TLS is enabled and user wasn't in TLS before: |
| 603 | 602 | // - Sets TLS session flag |
| … | … | … |
| 607 | 606 | |
| 608 | 607 | ==== Example 3: Invalidating Cache After Page Edit ==== |
| 609 | 608 | |
| 610 |
%% |
|
| 609 | %%(hl php) | |
| 611 | 610 | // User edits a page |
| 612 | 611 | $http = new Http($db); |
| 613 | 612 | $count = $http->invalidate_page('HomePage'); |
| … | … | … |
| 616 | 615 | |
| 617 | 616 | ==== Example 4: Serving a File ==== |
| 618 | 617 | |
| 619 |
%% |
|
| 618 | %%(hl php) | |
| 620 | 619 | $http = new Http($db); |
| 621 | 620 | $http->session(2); // Static file mode - no session replay prevention |
| 622 | 621 | |
| … | … | … |
| 691 | 690 | |
| 692 | 691 | The class integrates with WackoWiki's diagnostic system: |
| 693 | 692 | |
| 694 |
%% |
|
| 693 | %%(hl php) | |
| 695 | 694 | // Diagnostic messages are preserved across redirects |
| 696 | 695 | // via session flash data |
| 697 | 696 |