From 7d757a91ff6cf41ddc8e02346ef4c7b2dd64c3a0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 4 Dec 2022 22:54:18 +0100 Subject: [PATCH] Request::getRemoteHost() does not perform DNS resolving [Closes #218] --- src/Http/Request.php | 4 ---- tests/Http/RequestFactory.proxy.forwarded.phpt | 8 ++++---- tests/Http/RequestFactory.proxy.x-forwarded.phpt | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Http/Request.php b/src/Http/Request.php index 984ebea3..d97c9375 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -254,10 +254,6 @@ public function getRemoteAddress(): ?string */ public function getRemoteHost(): ?string { - if ($this->remoteHost === null && $this->remoteAddress !== null) { - $this->remoteHost = gethostbyaddr($this->remoteAddress); - } - return $this->remoteHost; } diff --git a/tests/Http/RequestFactory.proxy.forwarded.phpt b/tests/Http/RequestFactory.proxy.forwarded.phpt index 1f364e1b..b8ed7851 100644 --- a/tests/Http/RequestFactory.proxy.forwarded.phpt +++ b/tests/Http/RequestFactory.proxy.forwarded.phpt @@ -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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated $url = $factory->fromGlobals()->getUrl(); Assert::same('http', $url->getScheme()); @@ -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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated $url = $factory->fromGlobals()->getUrl(); Assert::same(8080, $url->getPort()); @@ -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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated $url = $factory->fromGlobals()->getUrl(); Assert::same('2001:db8:cafe::18', $url->getHost()); @@ -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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated $url = $factory->fromGlobals()->getUrl(); Assert::same(47832, $url->getPort()); diff --git a/tests/Http/RequestFactory.proxy.x-forwarded.phpt b/tests/Http/RequestFactory.proxy.x-forwarded.phpt index e91151e3..ec7a0ad4 100644 --- a/tests/Http/RequestFactory.proxy.x-forwarded.phpt +++ b/tests/Http/RequestFactory.proxy.x-forwarded.phpt @@ -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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated $url = $factory->fromGlobals()->getUrl(); Assert::same('otherhost', $url->getHost()); @@ -44,11 +44,11 @@ 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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated Assert::same('real', $factory->fromGlobals()->getUrl()->getHost()); $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()); // deprecated + Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated Assert::same('real', $factory->fromGlobals()->getUrl()->getHost()); });