Skip to content

Commit bf06626

Browse files
committed
#15 - Add
1 parent 3c21c40 commit bf06626

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/TgUtils/Request.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public static function getRequest() {
3838
public $uri;
3939
/** The path of the request. Does not include parameters */
4040
public $path;
41+
/** The path of the original request (requested at proxy). Does not include parameters */
42+
public $originalPath;
4143
/** The path split in its elements */
4244
public $pathElements;
4345
/** The parameters as a string */
@@ -89,6 +91,7 @@ public function __construct() {
8991
$this->body = NULL;
9092
$this->documentRoot = $this->initDocumentRoot();
9193
$this->webRoot = $this->initWebRoot(TRUE);
94+
$this->originalPath = $this->initOriginalPath();
9295
$this->localWebRoot = $this->initWebRoot(FALSE);
9396
$this->webRootUri = $this->initWebRootUri();
9497
$this->appRoot = $this->documentRoot;
@@ -285,7 +288,24 @@ protected function initDocumentRoot() {
285288
}
286289
return $_SERVER['DOCUMENT_ROOT'];
287290
}
288-
291+
292+
/**
293+
* Returns the original path as request by the end user.
294+
* The path might be different from $this->path as
295+
* a webroot mapping might be involved.
296+
*/
297+
protected function initOriginalPath() {
298+
$rc = $this->path;
299+
$rootDef = $_SERVER['HTTP_X_FORWARDED_ROOT'];
300+
if ($rootDef) {
301+
$arr = explode(',', $rootDef);
302+
if (strpos($rc, $arr[0]) === 0) {
303+
$rc = $arr[1].substr($rc, strlen($arr[0]));
304+
}
305+
}
306+
return $rc;
307+
}
308+
289309
/**
290310
* Returns the web root - that is the web path where the current
291311
* script is rooted and usually the base path for an application.

0 commit comments

Comments
 (0)