Skip to content

Commit e0d834e

Browse files
committed
fix: Get Requested Path
1 parent 2e59a68 commit e0d834e

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

tests/webfiori/tests/http/RequestTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,16 @@ public function testGetRequestedURL04() {
138138
* @test
139139
*/
140140
public function testGetRequestedURL05() {
141-
putenv('REQUEST_URI=');
141+
putenv('REQUEST_URI');
142142
putenv('HTTP_REQUEST_URI=/A/B/C');
143143
$this->assertEquals('http://127.0.0.1/A/B/C', Request::getRequestedURI());
144144
}
145145
/**
146146
* @test
147147
*/
148148
public function testGetRequestedURL06() {
149-
putenv('REQUEST_URI=');
150-
putenv('HTTP_REQUEST_URI=');
149+
putenv('REQUEST_URI');
150+
putenv('HTTP_REQUEST_URI');
151151
$_SERVER['HTTP_X_ORIGINAL_URL'] = 'https://example.com/a/good/boy';
152152
$this->assertEquals('http://127.0.0.1/a/good/boy', Request::getRequestedURI());
153153
unset($_SERVER['HTTP_X_ORIGINAL_URL']);

webfiori/http/HeadersPool.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ public function getHeader(string $name) : array {
8888
/**
8989
* Returns the value(s) of specific HTTP header as an array of objects.
9090
*
91-
* @param string $name The name of the header.
91+
* @param string $name The name of the header. Note that if name contains
92+
* underscore (_), it will be replaced by a dash (-).
9293
*
9394
* @return array If such header exist, the method will return an array
9495
* that contains the values of the header stored as objects of type
9596
* HttpHeader. If the header does not exist, the array will be empty.
9697
*/
9798
public function getHeaderAsObj(string $name) : array {
9899
$retVal = [];
99-
$trimmed = strtolower(trim($name));
100-
100+
$trimmed = str_replace('_', '-', strtolower(trim($name)));
101+
101102
foreach ($this->getHeaders() as $headerObj) {
102103
if ($headerObj->getName() == $trimmed) {
103104
$retVal[] = $headerObj;

webfiori/http/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public static function getHeader(string $name) : array {
169169
* @since 1.0
170170
*/
171171
public static function getHeaders() : array {
172-
if (defined('__PHPUNIT_PHAR__') || self::get()->headersPool === null) {
172+
if (defined('__PHPUNIT_PHAR__') || self::get()->headersPool === null || http_response_code() === false) {
173173
//Always Refresh headers if in testing environment.
174174
self::extractHeaders();
175175
}
@@ -301,7 +301,7 @@ public static function getPath() : string {
301301
$path = self::getPathHelper('REQUEST_URI');
302302

303303
if (strlen($path) == 0) {
304-
$path = self::getPathHelper('HTTP_X_ORIGINAL_URL');
304+
$path = self::getPathHelper('X_ORIGINAL_URL');
305305

306306
if (strlen($path) == 0) {
307307
$path = getenv('REQUEST_URI');

0 commit comments

Comments
 (0)