Skip to content

Commit

Permalink
Retrieve URL
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Apr 24, 2020
1 parent 61eb09e commit 2cfeea7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 2cfeea7

Please sign in to comment.