diff --git a/src/Request.php b/src/Request.php index a9665b2..efb75cc 100644 --- a/src/Request.php +++ b/src/Request.php @@ -182,6 +182,11 @@ public function urlSprintf($format = "%a") return str_replace(array_keys($this->_formatCache), $this->_formatCache, $format); } + public function url() + { + return $this->getSchemeAndHttpHost() . $this->getRequestUri(); + } + /** * Detect if the port is the standard based on the scheme e.g. http = 80 * diff --git a/tests/RequestTest.php b/tests/RequestTest.php index c9340d1..8341cdc 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -273,4 +273,12 @@ public function testAppEngineIp() $classicRequest->headers->set('x-appengine-user-ip', '0.0.0.0'); //fake ip through header $this->assertEquals(['1.2.3.4', '5.6.7.8'], $classicRequest->getClientIps()); } + + public function testUrl() + { + $request = Request::createFromGlobals(); + $request->headers->set('HOST', 'www.packaged.local:81'); + $request->server->set('REQUEST_URI', '/path/uri'); + $this->assertEquals('http://www.packaged.local:81/path/uri', $request->url()); + } }