Skip to content

Commit 50c8ecf

Browse files
committed
Update Request.php
Fixed a bug which can happen when using the library in built-in php server.
1 parent dd05d00 commit 50c8ecf

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/Request.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,17 @@ public static function getContentType() {
132132
* @since 1.0
133133
*/
134134
public static function getMethod() {
135-
$method = filter_var(getenv('REQUEST_METHOD'), FILTER_SANITIZE_STRING);
136-
135+
$meth = getenv('REQUEST_METHOD');
136+
137+
if ($meth === false) {
138+
$meth = $_SERVER['REQUEST_METHOD'];
139+
}
140+
$method = filter_var($meth, FILTER_SANITIZE_STRING);
141+
142+
if ($method === false) {
143+
144+
}
145+
137146
if (!in_array($method, self::METHODS)) {
138147
$method = 'GET';
139148
}
@@ -150,9 +159,17 @@ public static function getMethod() {
150159
public static function getRequestedURL() {
151160
if (self::get()->requestedUri === null) {
152161
$base = Uri::getBaseURL();
162+
$uri = getenv('REQUEST_URI');
153163

154-
$requestedURI = trim(filter_var(getenv('REQUEST_URI')),'/');
155-
self::get()->requestedUri = $base.'/'.$requestedURI;
164+
if ($uri === false) {
165+
// Using built-in server, it will be false
166+
$path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
167+
self::get()->requestedUri = $base.'/'.trim(filter_var($path),'/');
168+
} else {
169+
$requestedURI = trim(filter_var($uri),'/');
170+
171+
self::get()->requestedUri = $base.'/'.$requestedURI;
172+
}
156173
}
157174

158175

0 commit comments

Comments
 (0)