| 39 |
%% ||
|
45 |
%%
|
| 40 |
|| **Purpose:** Initializes the Http object and sets up HTTP session handling. ||
|
46 |
|
| 41 |
|| **Parameters:** ||
|
47 |
**Purpose:** Initializes the Http object and sets up HTTP session handling.
|
| 42 |
|| - ##$db## - Database object reference ||
|
48 |
|
| 43 |
|| **Initialization Steps:** ||
|
49 |
**Parameters:**
|
| 44 |
|| 1. Stores database reference ||
|
50 |
- ##$db## - Database object reference
|
| 45 |
|| 2. Extracts and normalizes REQUEST_URI ||
|
51 |
|
| 46 |
|| 3. Detects TLS/HTTPS session status ||
|
52 |
**Initialization Steps:**
|
| 47 |
|| 4. Determines client's real IP address ||
|
53 |
1. Stores database reference
|
| 48 |
|| 5. Sets up TLS mark cookie name ||
|
54 |
2. Extracts and normalizes REQUEST_URI
|
| 49 |
|| 6. Enforces TLS session upgrade if needed ||
|
55 |
3. Detects TLS/HTTPS session status
|
| 50 |
|| **Example:** ||
|
56 |
4. Determines client's real IP address
|
| 51 |
|| %%php
|
57 |
5. Sets up TLS mark cookie name
|
| |
|
58 |
6. Enforces TLS session upgrade if needed
|
| |
|
59 |
|
| |
|
60 |
**Example:**
|
| |
|
61 |
%%php
|
| 53 |
%% ||
|
63 |
%%
|
| 54 |
|| ---- ||
|
64 |
|
| 55 |
|| === Core Methods === ||
|
65 |
----
|
| 56 |
|| ==== Session Management ==== ||
|
66 |
|
| 57 |
|| ===== ##session($route): void## ===== ||
|
67 |
=== Core Methods ===
|
| 58 |
|| Initializes the session handler (file-based or database-based). ||
|
68 |
|
| 59 |
|| **Parameters:** ||
|
69 |
==== Session Management ====
|
| 60 |
|| - ##$route## (int) - Routing flag: ||
|
70 |
|
| 61 |
|| - Bit 2 (##$route & 2##): Enable static mode for files/freecap (disables replay prevention and ID regeneration) ||
|
71 |
===== ##session($route): void## =====
|
| 62 |
|| **Features:** ||
|
72 |
Initializes the session handler (file-based or database-based).
|
| 63 |
|| - Selects storage backend (file or database) ||
|
73 |
|
| 64 |
|| - Configures cookie settings (security, path, httponly) ||
|
74 |
**Parameters:**
|
| 65 |
|| - Binds IP and TLS validation ||
|
75 |
- ##$route## (int) - Routing flag:
|
| 66 |
|| - Recovers diagnostic logs from previous session ||
|
76 |
- Bit 2 (##$route & 2##): Enable static mode for files/freecap (disables replay prevention and ID regeneration)
|
| 67 |
|| **Example:** ||
|
77 |
|
| 68 |
|| %%php
|
78 |
**Features:**
|
| |
|
79 |
- Selects storage backend (file or database)
|
| |
|
80 |
- Configures cookie settings (security, path, httponly)
|
| |
|
81 |
- Binds IP and TLS validation
|
| |
|
82 |
- Recovers diagnostic logs from previous session
|
| |
|
83 |
|
| |
|
84 |
**Example:**
|
| |
|
85 |
%%php
|
| 71 |
%% ||
|
88 |
%%
|
| 72 |
|| ---- ||
|
89 |
|
| 73 |
|| ==== Caching System ==== ||
|
90 |
----
|
| 74 |
|| ===== ##check_cache($page, $method): void## ===== ||
|
91 |
|
| 75 |
|| Determines if a page can be cached and prepares the cache check. ||
|
92 |
==== Caching System ====
|
| 76 |
|| **Parameters:** ||
|
93 |
|
| 77 |
|| - ##$page## (string) - Page name to cache ||
|
94 |
===== ##check_cache($page, $method): void## =====
|
| 78 |
|| - ##$method## (string) - Request method/action (e.g., 'show', 'edit') ||
|
95 |
Determines if a page can be cached and prepares the cache check.
|
| 79 |
|| **Caching Rules:** ||
|
96 |
|
| 80 |
|| - ✅ Enabled for GET requests only ||
|
97 |
**Parameters:**
|
| 81 |
|| - ✅ Disabled for POST requests ||
|
98 |
- ##$page## (string) - Page name to cache
|
| 82 |
|| - ❌ Never cached for 'edit' or 'watch' methods ||
|
99 |
- ##$method## (string) - Request method/action (e.g., 'show', 'edit')
|
| 83 |
|| - ✅ Only cached for anonymous users (no logged-in users) ||
|
100 |
|
| 84 |
|| **Example:** ||
|
101 |
**Caching Rules:**
|
| 85 |
|| %%php
|
102 |
- ✅ Enabled for GET requests only
|
| |
|
103 |
- ✅ Disabled for POST requests
|
| |
|
104 |
- ❌ Never cached for 'edit' or 'watch' methods
|
| |
|
105 |
- ✅ Only cached for anonymous users (no logged-in users)
|
| |
|
106 |
|
| |
|
107 |
**Example:**
|
| |
|
108 |
%%php
|
| 87 |
%% ||
|
110 |
%%
|
| 88 |
|| ---- ||
|
111 |
|
| 89 |
|| ===== ##store_cache(): void## ===== ||
|
112 |
----
|
| 90 |
|| Saves the generated page content to cache file. ||
|
113 |
|
| 91 |
|| **Features:** ||
|
114 |
===== ##store_cache(): void## =====
|
| 92 |
|| - Retrieves output buffer content ||
|
115 |
Saves the generated page content to cache file.
|
| 93 |
|| - Saves to cache file with proper permissions ||
|
116 |
|
| 94 |
|| - Records cache metadata in database ||
|
117 |
**Features:**
|
| 95 |
|| - Only executes if caching flag is set and user is anonymous ||
|
118 |
- Retrieves output buffer content
|
| 96 |
|| **Example:** ||
|
119 |
- Saves to cache file with proper permissions
|
| 97 |
|| %%php
|
120 |
- Records cache metadata in database
|
| |
|
121 |
- Only executes if caching flag is set and user is anonymous
|
| |
|
122 |
|
| |
|
123 |
**Example:**
|
| |
|
124 |
%%php
|
| 100 |
%% ||
|
127 |
%%
|
| 101 |
|| ---- ||
|
128 |
|
| 102 |
|| ===== ##invalidate_page($page): int## ===== ||
|
129 |
----
|
| 103 |
|| Invalidates all cached versions of a page. ||
|
130 |
|
| 104 |
|| **Parameters:** ||
|
131 |
===== ##invalidate_page($page): int## =====
|
| 105 |
|| - ##$page## (string) - Page name to invalidate ||
|
132 |
Invalidates all cached versions of a page.
|
| 106 |
|| **Returns:** ||
|
133 |
|
| 107 |
|| - Number of cache entries invalidated ||
|
134 |
**Parameters:**
|
| 108 |
|| **Process:** ||
|
135 |
- ##$page## (string) - Page name to invalidate
|
| 109 |
|| 1. Finds all cached versions (different methods/languages) ||
|
136 |
|
| 110 |
|| 2. Touches files to past timestamp (faster than deletion) ||
|
137 |
**Returns:**
|
| 111 |
|| 3. Removes entries from cache metadata table ||
|
138 |
- Number of cache entries invalidated
|
| 112 |
|| 4. Returns count of invalidated caches ||
|
139 |
|
| 113 |
|| **Example:** ||
|
140 |
**Process:**
|
| 114 |
|| %%php
|
141 |
1. Finds all cached versions (different methods/languages)
|
| |
|
142 |
2. Touches files to past timestamp (faster than deletion)
|
| |
|
143 |
3. Removes entries from cache metadata table
|
| |
|
144 |
4. Returns count of invalidated caches
|
| |
|
145 |
|
| |
|
146 |
**Example:**
|
| |
|
147 |
%%php
|
| 117 |
%% ||
|
150 |
%%
|
| 118 |
|| ---- ||
|
151 |
|
| 119 |
|| ==== TLS/HTTPS Security ==== ||
|
152 |
----
|
| 120 |
|| ===== ##secure_base_url(): void## ===== ||
|
153 |
|
| 121 |
|| Switches base URL from HTTP to HTTPS. ||
|
154 |
==== TLS/HTTPS Security ====
|
| 122 |
|| **Purpose:** ||
|
155 |
|
| 123 |
|| - Ensures all subsequent URLs use HTTPS ||
|
156 |
===== ##secure_base_url(): void## =====
|
| 124 |
|| - Stores original HTTP URL for fallback ||
|
157 |
Switches base URL from HTTP to HTTPS.
|
| 125 |
|| - Called when TLS session is detected ||
|
158 |
|
| 126 |
|| **Example:** ||
|
159 |
**Purpose:**
|
| 127 |
|| %%php
|
160 |
- Ensures all subsequent URLs use HTTPS
|
| |
|
161 |
- Stores original HTTP URL for fallback
|
| |
|
162 |
- Called when TLS session is detected
|
| |
|
163 |
|
| |
|
164 |
**Example:**
|
| |
|
165 |
%%php
|
| 130 |
%% ||
|
168 |
%%
|
| 131 |
|| ---- ||
|
169 |
|
| 132 |
|| ===== ##ensure_tls($url): void## ===== ||
|
170 |
----
|
| 133 |
|| Enforces HTTPS for a specific URL and redirects if necessary. ||
|
171 |
|
| 134 |
|| **Parameters:** ||
|
172 |
===== ##ensure_tls($url): void## =====
|
| 135 |
|| - ##$url## (string) - URL to secure ||
|
173 |
Enforces HTTPS for a specific URL and redirects if necessary.
|
| 136 |
|| **Behavior:** ||
|
174 |
|
| 137 |
|| - If not already HTTPS and TLS is enabled, forces HTTPS redirect ||
|
175 |
**Parameters:**
|
| 138 |
|| - Handles both relative and absolute URLs ||
|
176 |
- ##$url## (string) - URL to secure
|
| 139 |
|| - Converts relative URLs using current server name ||
|
177 |
|
| 140 |
|| **Example:** ||
|
178 |
**Behavior:**
|
| 141 |
|| %%php
|
179 |
- If not already HTTPS and TLS is enabled, forces HTTPS redirect
|
| |
|
180 |
- Handles both relative and absolute URLs
|
| |
|
181 |
- Converts relative URLs using current server name
|
| |
|
182 |
|
| |
|
183 |
**Example:**
|
| |
|
184 |
%%php
|
| 143 |
%% ||
|
186 |
%%
|
| 144 |
|| ---- ||
|
187 |
|
| 145 |
|| ==== IP Address Detection ==== ||
|
188 |
----
|
| 146 |
|| ===== ##real_ip(): string## (Private) ===== ||
|
189 |
|
| 147 |
|| Detects client's real IP address accounting for proxies. ||
|
190 |
==== IP Address Detection ====
|
| 148 |
|| **Proxy Headers Checked (in order):** ||
|
191 |
|
| 149 |
|| 1. ##HTTP_X_CLUSTER_CLIENT_IP## ||
|
192 |
===== ##real_ip(): string## (Private) =====
|
| 150 |
|| 2. ##HTTP_X_FORWARDED_FOR## (or custom header) ||
|
193 |
Detects client's real IP address accounting for proxies.
|
| 151 |
|| 3. ##HTTP_CLIENT_IP## ||
|
194 |
|
| 152 |
|| 4. ##HTTP_X_REMOTE_ADDR## ||
|
195 |
**Proxy Headers Checked (in order):**
|
| 153 |
|| 5. ##REMOTE_ADDR## (fallback) ||
|
196 |
1. ##HTTP_X_CLUSTER_CLIENT_IP##
|
| 154 |
|| **Features:** ||
|
197 |
2. ##HTTP_X_FORWARDED_FOR## (or custom header)
|
| 155 |
|| - Filters out private/reserved IP ranges ||
|
198 |
3. ##HTTP_CLIENT_IP##
|
| 156 |
|| - Respects configured reverse proxy addresses ||
|
199 |
4. ##HTTP_X_REMOTE_ADDR##
|
| 157 |
|| - Returns ##'0.0.0.0'## as fallback ||
|
200 |
5. ##REMOTE_ADDR## (fallback)
|
| 158 |
|| **Configuration in Database:** ||
|
201 |
|
| 159 |
|| - ##reverse_proxy_addresses## - Comma/space-separated proxy IPs ||
|
202 |
**Features:**
|
| 160 |
|| - ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##) ||
|
203 |
- Filters out private/reserved IP ranges
|
| 161 |
|| **Example:** ||
|
204 |
- Respects configured reverse proxy addresses
|
| 162 |
|| %%php
|
205 |
- Returns ##'0.0.0.0'## as fallback
|
| |
|
206 |
|
| |
|
207 |
**Configuration in Database:**
|
| |
|
208 |
- ##reverse_proxy_addresses## - Comma/space-separated proxy IPs
|
| |
|
209 |
- ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##)
|
| |
|
210 |
|
| |
|
211 |
**Example:**
|
| |
|
212 |
%%php
|
| 164 |
%% ||
|
214 |
%%
|
| 165 |
|| ---- ||
|
215 |
|
| 166 |
|| ==== HTTPS Detection ==== ||
|
216 |
----
|
| 167 |
|| ===== ##tls_session(): bool## (Private) ===== ||
|
217 |
|
| 168 |
|| Detects if current connection uses HTTPS/TLS. ||
|
218 |
==== HTTPS Detection ====
|
| 169 |
|| **Checks (any being true = HTTPS):** ||
|
219 |
|
| 170 |
|| - ##$_SERVER['HTTPS']## is 'on' ||
|
220 |
===== ##tls_session(): bool## (Private) =====
|
| 171 |
|| - ##$_SERVER['SERVER_PORT']## is 443 ||
|
221 |
Detects if current connection uses HTTPS/TLS.
|
| 172 |
|| - ##$_SERVER['HTTP_X_FORWARDED_PROTO']## is 'https' ||
|
222 |
|
| 173 |
|| - ##$_SERVER['HTTP_X_FORWARDED_SSL']## is 'on' ||
|
223 |
**Checks (any being true = HTTPS):**
|
| 174 |
|| - ##$_SERVER['HTTP_X_FORWARDED_PORT']## is 443 ||
|
224 |
- ##$_SERVER['HTTPS']## is 'on'
|
| 175 |
|| ---- ||
|
225 |
- ##$_SERVER['SERVER_PORT']## is 443
|
| 176 |
|| ==== Security Headers ==== ||
|
226 |
- ##$_SERVER['HTTP_X_FORWARDED_PROTO']## is 'https'
|
| 177 |
|| ===== ##http_security_headers(): void## ===== ||
|
227 |
- ##$_SERVER['HTTP_X_FORWARDED_SSL']## is 'on'
|
| 178 |
|| Sets security-related HTTP headers. ||
|
228 |
- ##$_SERVER['HTTP_X_FORWARDED_PORT']## is 443
|
| 179 |
|| **Headers Set:** ||
|
229 |
|
| 180 |
|| Header | Purpose | Config Key ||
|
230 |
----
|
| 181 |
|| -------- | --------- | ------------ ||
|
231 |
|
| |
|
232 |
==== Security Headers ====
|
| |
|
233 |
|
| |
|
234 |
=====##http_security_headers(): void##=====
|
| |
|
235 |
|
| |
|
236 |
Sets security-related HTTP headers.
|
| |
|
237 |
|
| |
|
238 |
**Headers Set:**
|
| |
|
239 |
|
| |
|
240 |
#|
|
| |
|
241 |
*| Header | Purpose | Config Key |*
|
| 182 |
|| Content-Security-Policy | XSS/injection protection | ##csp## ||
|
242 |
|| Content-Security-Policy | XSS/injection protection | ##csp## ||
|
| 183 |
|| Permissions-Policy | Control browser features | ##permissions_policy## ||
|
243 |
|| Permissions-Policy | Control browser features | ##permissions_policy## ||
|
| 184 |
|| Referrer-Policy | Control referrer information | ##referrer_policy## ||
|
244 |
|| Referrer-Policy | Control referrer information | ##referrer_policy## ||
|
| 185 |
|| Strict-Transport-Security | Force HTTPS | Auto (TLS only) ||
|
245 |
|| Strict-Transport-Security | Force HTTPS | Auto (TLS only) ||
|
| 186 |
|| X-Frame-Options | Clickjacking protection | Hardcoded: ##SAMEORIGIN## ||
|
246 |
|| X-Frame-Options | Clickjacking protection | Hardcoded: ##SAMEORIGIN## ||
|
| 187 |
|| X-Content-Type-Options | MIME sniffing prevention | Hardcoded: ##nosniff## ||
|
247 |
|| X-Content-Type-Options | MIME sniffing prevention | Hardcoded: ##nosniff## ||
|
| 195 |
%% ||
|
258 |
%%
|
| 196 |
|| ---- ||
|
259 |
|
| 197 |
|| ==== HTTP Methods ==== ||
|
260 |
----
|
| 198 |
|| ===== ##redirect($url, $permanent = false): void## ===== ||
|
261 |
==== HTTP Methods ====
|
| 199 |
|| Performs an HTTP redirect. ||
|
262 |
|
| 200 |
|| **Parameters:** ||
|
263 |
===== ##redirect($url, $permanent = false): void## =====
|
| 201 |
|| - ##$url## (string) - Target URL ||
|
264 |
Performs an HTTP redirect.
|
| 202 |
|| - ##$permanent## (bool) - Use 301 (permanent) vs 302 (temporary) ||
|
265 |
|
| 203 |
|| **Features:** ||
|
266 |
**Parameters:**
|
| 204 |
|| - Decodes ##&## entities to prevent broken redirects ||
|
267 |
- ##$url## (string) - Target URL
|
| 205 |
|| - Only works if headers not yet sent ||
|
268 |
- ##$permanent## (bool) - Use 301 (permanent) vs 302 (temporary)
|
| 206 |
|| - Uses output buffering to work anywhere in page processing ||
|
269 |
|
| 207 |
|| **Example:** ||
|
270 |
**Features:**
|
| 208 |
|| %%php
|
271 |
- Decodes ##&## entities to prevent broken redirects
|
| |
|
272 |
- Only works if headers not yet sent
|
| |
|
273 |
- Uses output buffering to work anywhere in page processing
|
| |
|
274 |
|
| |
|
275 |
**Example:**
|
| |
|
276 |
%%php
|
| 247 |
%% ||
|
323 |
%%
|
| 248 |
|| ---- ||
|
324 |
|
| 249 |
|| ==== Caching Control ==== ||
|
325 |
----
|
| 250 |
|| ===== ##no_cache($client_only = true): void## ===== ||
|
326 |
|
| 251 |
|| Disables caching of the current page. ||
|
327 |
==== Caching Control ====
|
| 252 |
|| **Parameters:** ||
|
328 |
|
| 253 |
|| - ##$client_only## (bool, default: TRUE) ||
|
329 |
===== ##no_cache($client_only = true): void## =====
|
| 254 |
|| - ##TRUE##: Disable browser cache only ||
|
330 |
Disables caching of the current page.
|
| 255 |
|| - ##FALSE##: Disable both browser and server cache ||
|
331 |
|
| 256 |
|| **Headers Set:** ||
|
332 |
**Parameters:**
|
| 257 |
|| - ##Last-Modified: <current-time>## (always fresh) ||
|
333 |
- ##$client_only## (bool, default: TRUE)
|
| 258 |
|| - ##Cache-Control: no-store## ||
|
334 |
- ##TRUE##: Disable browser cache only
|
| 259 |
|| **Example:** ||
|
335 |
- ##FALSE##: Disable both browser and server cache
|
| 260 |
|| %%php
|
336 |
|
| |
|
337 |
**Headers Set:**
|
| |
|
338 |
- ##Last-Modified: <current-time>## (always fresh)
|
| |
|
339 |
- ##Cache-Control: no-store##
|
| |
|
340 |
|
| |
|
341 |
**Example:**
|
| |
|
342 |
%%php
|
| 272 |
%% ||
|
358 |
%%
|
| 273 |
|| ---- ||
|
359 |
|
| 274 |
|| ==== Language Negotiation ==== ||
|
360 |
----
|
| 275 |
|| ===== ##user_agent_language(): string## ===== ||
|
361 |
|
| 276 |
|| Determines best language based on browser preferences. ||
|
362 |
==== Language Negotiation ====
|
| 277 |
|| **Features:** ||
|
363 |
|
| 278 |
|| - Follows RFC 9110 section 12.5.4 (HTTP Accept-Language) ||
|
364 |
===== ##user_agent_language(): string## =====
|
| 279 |
|| - Parses ##Accept-Language## header with quality factors ||
|
365 |
Determines best language based on browser preferences.
|
| 280 |
|| - Attempts exact match first, then language fallback ||
|
366 |
|
| 281 |
|| - Falls back to default system language ||
|
367 |
**Features:**
|
| 282 |
|| **Example Header:** ||
|
368 |
- Follows RFC 9110 section 12.5.4 (HTTP Accept-Language)
|
| 283 |
|| %%
|
369 |
- Parses ##Accept-Language## header with quality factors
|
| |
|
370 |
- Attempts exact match first, then language fallback
|
| |
|
371 |
- Falls back to default system language
|
| |
|
372 |
|
| |
|
373 |
**Example Header:**
|
| |
|
374 |
%%
|
| 285 |
%% ||
|
376 |
%%
|
| 286 |
|| **Returns:** ||
|
377 |
|
| 287 |
|| - Language code (e.g., 'en', 'en-US', 'de') ||
|
378 |
**Returns:**
|
| 288 |
|| ---- ||
|
379 |
- Language code (e.g., 'en', 'en-US', 'de')
|
| 289 |
|| ===== ##available_languages($subset = true): array## ===== ||
|
380 |
|
| 290 |
|| Returns list of available language translations. ||
|
381 |
----
|
| 291 |
|| **Parameters:** ||
|
382 |
|
| 292 |
|| - ##$subset## (bool, default: TRUE) ||
|
383 |
===== ##available_languages($subset = true): array## =====
|
| 293 |
|| - ##TRUE##: Only allowed languages ||
|
384 |
Returns list of available language translations.
|
| 294 |
|| - ##FALSE##: All available languages ||
|
385 |
|
| 295 |
|| **Features:** ||
|
386 |
**Parameters:**
|
| 296 |
|| - Scans ##LANG_DIR## for language files ||
|
387 |
- ##$subset## (bool, default: TRUE)
|
| 297 |
|| - Filters by ##allowed_languages## config if set ||
|
388 |
- ##TRUE##: Only allowed languages
|
| 298 |
|| - Caches result in session ||
|
389 |
- ##FALSE##: All available languages
|
| 299 |
|| - System language always included ||
|
390 |
|
| 300 |
|| **Returns:** ||
|
391 |
**Features:**
|
| 301 |
|| - Associative array: ##['en' => 'en', 'de' => 'de', ...]## ||
|
392 |
- Scans ##LANG_DIR## for language files
|
| 302 |
|| **Example:** ||
|
393 |
- Filters by ##allowed_languages## config if set
|
| 303 |
|| %%php
|
394 |
- Caches result in session
|
| |
|
395 |
- System language always included
|
| |
|
396 |
|
| |
|
397 |
**Returns:**
|
| |
|
398 |
- Associative array: ##['en' => 'en', 'de' => 'de', ...]##
|
| |
|
399 |
|
| |
|
400 |
**Example:**
|
| |
|
401 |
%%php
|
| 306 |
%% ||
|
404 |
%%
|
| 307 |
|| ---- ||
|
405 |
|
| 308 |
|| ==== File Serving ==== ||
|
406 |
----
|
| 309 |
|| ===== ##sendfile($path, $filename = null, $age = null): void## ===== ||
|
407 |
|
| 310 |
|| Serves files with proper HTTP headers and caching. ||
|
408 |
==== File Serving ====
|
| 311 |
|| **Parameters:** ||
|
409 |
|
| 312 |
|| - ##$path## (string) - File path (or HTTP_XXX constant for error pages) ||
|
410 |
===== ##sendfile($path, $filename = null, $age = null): void## =====
|
| 313 |
|| - ##$filename## (string, optional) - Custom download filename ||
|
411 |
Serves files with proper HTTP headers and caching.
|
| 314 |
|| - ##$age## (int, optional) - Cache age in days ||
|
412 |
|
| 315 |
|| **Features:** ||
|
413 |
**Parameters:**
|
| 316 |
|| - HTTP range request support (partial file downloads) ||
|
414 |
- ##$path## (string) - File path (or HTTP_XXX constant for error pages)
|
| 317 |
|| - ETag and Last-Modified conditional requests ||
|
415 |
- ##$filename## (string, optional) - Custom download filename
|
| 318 |
|| - Proper MIME type detection ||
|
416 |
- ##$age## (int, optional) - Cache age in days
|
| 319 |
|| - Content-Security-Policy for special file types ||
|
417 |
|
| 320 |
|| - Streaming for large files ||
|
418 |
**Features:**
|
| 321 |
|| - GZip compression for text files ||
|
419 |
- HTTP range request support (partial file downloads)
|
| 322 |
|| **Special Paths:** ||
|
420 |
- ETag and Last-Modified conditional requests
|
| 323 |
|| %%php
|
421 |
- Proper MIME type detection
|
| |
|
422 |
- Content-Security-Policy for special file types
|
| |
|
423 |
- Streaming for large files
|
| |
|
424 |
- GZip compression for text files
|
| |
|
425 |
|
| |
|
426 |
**Special Paths:**
|
| |
|
427 |
%%php
|
| 330 |
%% ||
|
435 |
%%
|
| 331 |
|| ---- ||
|
436 |
|
| 332 |
|| ===== ##mime_type($path): string## ===== ||
|
437 |
----
|
| 333 |
|| Returns MIME type for a file. ||
|
438 |
|
| 334 |
|| **Returns:** ||
|
439 |
===== ##mime_type($path): string## =====
|
| 335 |
|| - MIME type string (e.g., 'application/pdf') ||
|
440 |
Returns MIME type for a file.
|
| 336 |
|| - Default: ##'application/octet-stream'## ||
|
441 |
|
| 337 |
|| **Example:** ||
|
442 |
**Returns:**
|
| 338 |
|| %%php
|
443 |
- MIME type string (e.g., 'application/pdf')
|
| |
|
444 |
- Default: ##'application/octet-stream'##
|
| |
|
445 |
|
| |
|
446 |
**Example:**
|
| |
|
447 |
%%php
|
| 340 |
%% ||
|
449 |
%%
|
| 341 |
|| ---- ||
|
450 |
|
| 342 |
|| ===== ##mime_types(): array## (Private) ===== ||
|
451 |
----
|
| 343 |
|| Loads and caches MIME types from configuration. ||
|
452 |
|
| 344 |
|| **Features:** ||
|
453 |
===== ##mime_types(): array## (Private) =====
|
| 345 |
|| - Reads from ##config/mime.types## ||
|
454 |
Loads and caches MIME types from configuration.
|
| 346 |
|| - Caches to ##cache/config/mime.types## ||
|
455 |
|
| 347 |
|| - Reloads if config is updated ||
|
456 |
**Features:**
|
| 348 |
|| ---- ||
|
457 |
- Reads from ##config/mime.types##
|
| 349 |
|| ==== Compression ==== ||
|
458 |
- Caches to ##cache/config/mime.types##
|
| 350 |
|| ===== ##gzip(): void## ===== ||
|
459 |
- Reloads if config is updated
|
| 351 |
|| Compresses HTTP response with gzip/x-gzip. ||
|
460 |
|
| 352 |
|| **Features:** ||
|
461 |
----
|
| 353 |
|| - Manually implements gzip (not relying on zlib.output_compression) ||
|
462 |
|
| 354 |
|| - Produces correct ##Content-Length## header ||
|
463 |
==== Compression ====
|
| 355 |
|| - Only compresses if: ||
|
464 |
|
| 356 |
|| - 860 bytes < content < 1 MB ||
|
465 |
===== ##gzip(): void## =====
|
| 357 |
|| - Client accepts compression ||
|
466 |
Compresses HTTP response with gzip/x-gzip.
|
| 358 |
|| - Headers not already sent ||
|
467 |
|
| 359 |
|| **Example:** ||
|
468 |
**Features:**
|
| 360 |
|| %%php
|
469 |
- Manually implements gzip (not relying on zlib.output_compression)
|
| |
|
470 |
- Produces correct ##Content-Length## header
|
| |
|
471 |
- Only compresses if:
|
| |
|
472 |
- 860 bytes < content < 1 MB
|
| |
|
473 |
- Client accepts compression
|
| |
|
474 |
- Headers not already sent
|
| |
|
475 |
|
| |
|
476 |
**Example:**
|
| |
|
477 |
%%php
|
| 362 |
%% ||
|
479 |
%%
|
| 363 |
|| ---- ||
|
480 |
|
| 364 |
|| ==== Utility Methods ==== ||
|
481 |
----
|
| 365 |
|| ===== ##parse_str($str): array## (Private) ===== ||
|
482 |
|
| 366 |
|| Parses URL-encoded strings with special character handling. ||
|
483 |
==== Utility Methods ====
|
| 367 |
|| **Purpose:** ||
|
484 |
|
| 368 |
|| - Safely handles special characters in query/form data ||
|
485 |
===== ##parse_str($str): array## (Private) =====
|
| 369 |
|| - Converts encoding properly ||
|
486 |
Parses URL-encoded strings with special character handling.
|
| 370 |
|| **Example:** ||
|
487 |
|
| 371 |
|| %%php
|
488 |
**Purpose:**
|
| |
|
489 |
- Safely handles special characters in query/form data
|
| |
|
490 |
- Converts encoding properly
|
| |
|
491 |
|
| |
|
492 |
**Example:**
|
| |
|
493 |
%%php
|
| 373 |
%% ||
|
495 |
%%
|
| 374 |
|| ---- ||
|
496 |
|
| 375 |
|| ===== ##request_uri(): string## (Private) ===== ||
|
497 |
----
|
| 376 |
|| Extracts and normalizes REQUEST_URI from server. ||
|
498 |
|
| 377 |
|| **Normalization:** ||
|
499 |
===== ##request_uri(): string## (Private) =====
|
| 378 |
|| - Removes base URL prefix ||
|
500 |
Extracts and normalizes REQUEST_URI from server.
|
| 379 |
|| - Removes spaces ||
|
501 |
|
| 380 |
|| - Collapses multiple slashes ||
|
502 |
**Normalization:**
|
| 381 |
|| - Removes ##..## path traversal attempts ||
|
503 |
- Removes base URL prefix
|
| 382 |
|| - Removes leading/trailing slashes ||
|
504 |
- Removes spaces
|
| 383 |
|| ---- ||
|
505 |
- Collapses multiple slashes
|
| 384 |
|| ===== ##cut_prefix($prefix, $path): string## (Private) ===== ||
|
506 |
- Removes ##..## path traversal attempts
|
| 385 |
|| Removes prefix from path (case-insensitive). ||
|
507 |
- Removes leading/trailing slashes
|
| 386 |
|| ---- ||
|
508 |
|
| 387 |
|| ===== ##get_header_conf($file_name): string## (Private) ===== ||
|
509 |
----
|
| 388 |
|| Loads security header configuration from files. ||
|
510 |
|
| 389 |
|| **Files Supported:** ||
|
511 |
===== ##cut_prefix($prefix, $path): string## (Private) =====
|
| 390 |
|| - ##csp.conf## / ##csp_custom.conf## ||
|
512 |
Removes prefix from path (case-insensitive).
|
| 391 |
|| - ##permissions_policy.conf## / ##permissions_policy_custom.conf## ||
|
513 |
|
| 392 |
|| ---- ||
|
514 |
----
|
| 393 |
|| === Configuration Dependencies === ||
|
515 |
|
| 394 |
|| The class relies on these database configuration settings: ||
|
516 |
===== ##get_header_conf($file_name): string## (Private) =====
|
| 395 |
|| Setting | Type | Purpose ||
|
517 |
Loads security header configuration from files.
|
| 396 |
|| --------- | ------ | --------- ||
|
518 |
|
| |
|
519 |
**Files Supported:**
|
| |
|
520 |
- ##csp.conf## / ##csp_custom.conf##
|
| |
|
521 |
- ##permissions_policy.conf## / ##permissions_policy_custom.conf##
|
| |
|
522 |
|
| |
|
523 |
----
|
| |
|
524 |
|
| |
|
525 |
===Configuration Dependencies===
|
| |
|
526 |
|
| |
|
527 |
The class relies on these database configuration settings:
|
| |
|
528 |
|
| |
|
529 |
#|
|
| |
|
530 |
*| Setting | Type | Purpose |*
|