Skip to content

Commit 2e59a68

Browse files
committed
Update Request.php
1 parent 118753e commit 2e59a68

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

webfiori/http/Request.php

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,47 @@ public static function getParams() : array {
292292

293293
return $retVal;
294294
}
295+
/**
296+
* Returns path part of a requested URI.
297+
*
298+
* @return string Path part of a requested URI.
299+
*/
300+
public static function getPath() : string {
301+
$path = self::getPathHelper('REQUEST_URI');
302+
303+
if (strlen($path) == 0) {
304+
$path = self::getPathHelper('HTTP_X_ORIGINAL_URL');
305+
306+
if (strlen($path) == 0) {
307+
$path = getenv('REQUEST_URI');
308+
309+
if ($path === false || strlen($path) == 0) {
310+
$path = getenv('HTTP_REQUEST_URI');
311+
312+
if ($path === false || strlen($path) == 0) {
313+
//Local dev server
314+
$path = $_SERVER['PATH_INFO'] ?? '';
315+
}
316+
}
317+
}
318+
}
319+
320+
if (strlen($path) == 0) {
321+
return '/';
322+
}
323+
324+
return parse_url($path, PHP_URL_PATH);
325+
}
326+
private static function getPathHelper(string $header) {
327+
$path = '';
328+
$headerVals = self::getHeader($header);
329+
330+
if (count($headerVals) != 0) {
331+
$path = trim($headerVals[0]);
332+
}
333+
334+
return $path;
335+
}
295336
/**
296337
* Returns the URI of the requested resource.
297338
*
@@ -306,12 +347,8 @@ public static function getParams() : array {
306347
*/
307348
public static function getRequestedURI(string $pathToAppend = '') : string {
308349
$base = Uri::getBaseURL();
309-
$path = getenv('REQUEST_URI');
310-
311-
if ($path === false) {
312-
// Using built-in server, it will be false
313-
$path = $_SERVER['PATH_INFO'] ?? '';
314-
}
350+
351+
$path = self::getPath();
315352

316353
if (strpos($path, '?') !== false) {
317354
$split = explode('?', $path);

0 commit comments

Comments
 (0)