Skip to content

Commit

Permalink
Request::getRemoteHost() does not perform DNS resolving [Closes #218]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 5, 2024
1 parent f7f8979 commit 11b260d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@ public function getRemoteAddress(): ?string
*/
public function getRemoteHost(): ?string
{
if ($this->remoteHost === null && $this->remoteAddress !== null) {
$this->remoteHost = gethostbyaddr($this->remoteAddress);
}

return $this->remoteHost;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Http/RequestFactory.proxy.forwarded.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('', function () {

$factory->setProxy('127.0.0.1/8');
Assert::same('23.75.45.200', $factory->fromGlobals()->getRemoteAddress());
Assert::same('a23-75-45-200.deploy.static.akamaitechnologies.com', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('http', $url->getScheme());
Expand All @@ -43,7 +43,7 @@ test('', function () {

$factory->setProxy('127.0.0.3');
Assert::same('23.75.45.200', $factory->fromGlobals()->getRemoteAddress());
Assert::same('a23-75-45-200.deploy.static.akamaitechnologies.com', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same(8080, $url->getPort());
Expand All @@ -62,7 +62,7 @@ test('', function () {

$factory->setProxy('127.0.0.3');
Assert::same('2001:db8:cafe::17', $factory->fromGlobals()->getRemoteAddress());
Assert::same('2001:db8:cafe::17', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('[2001:db8:cafe::18]', $url->getHost());
Expand All @@ -79,7 +79,7 @@ test('', function () {

$factory->setProxy('127.0.0.3');
Assert::same('2001:db8:cafe::17', $factory->fromGlobals()->getRemoteAddress());
Assert::same('2001:db8:cafe::17', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same(47832, $url->getPort());
Expand Down
10 changes: 5 additions & 5 deletions tests/Http/RequestFactory.proxy.x-forwarded.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('', function () {

$factory->setProxy('127.0.0.1/8');
Assert::same('23.75.45.200', $factory->fromGlobals()->getRemoteAddress());
Assert::same('a23-75-45-200.deploy.static.akamaitechnologies.com', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('otherhost', $url->getHost());
Expand All @@ -45,7 +45,7 @@ test('', function () {
$factory = new RequestFactory;
$factory->setProxy('127.0.0.3');
Assert::same('23.75.45.200', $factory->fromGlobals()->getRemoteAddress());
Assert::same('a23-75-45-200.deploy.static.akamaitechnologies.com', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('otherhost', $url->getHost());
Expand Down Expand Up @@ -81,15 +81,15 @@ test('', function () {
$factory = new RequestFactory;
$factory->setProxy('10.0.0.0/24');
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('real', $url->getHost());
Assert::same(80, $url->getPort());

$factory->setProxy(['10.0.0.1', '10.0.0.2']);
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('real', $url->getHost());
Expand All @@ -107,7 +107,7 @@ test('', function () {
$factory = new RequestFactory;
$factory->setProxy(['10.0.0.1', '10.0.0.2']);
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteHost());
Assert::null($factory->fromGlobals()->getRemoteHost());

$url = $factory->fromGlobals()->getUrl();
Assert::same('real', $url->getHost());
Expand Down

0 comments on commit 11b260d

Please sign in to comment.