Skip to content

Commit b2a5951

Browse files
committed
Request::getRemoteHost() does not perform DNS resolving [Closes #218]
1 parent d96f69e commit b2a5951

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/Http/Request.php

-4
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,6 @@ public function getRemoteAddress(): ?string
254254
*/
255255
public function getRemoteHost(): ?string
256256
{
257-
if ($this->remoteHost === null && $this->remoteAddress !== null) {
258-
$this->remoteHost = gethostbyaddr($this->remoteAddress);
259-
}
260-
261257
return $this->remoteHost;
262258
}
263259

tests/Http/RequestFactory.proxy.forwarded.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test('', function () {
2525

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

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

4444
$factory->setProxy('127.0.0.3');
4545
Assert::same('23.75.45.200', $factory->fromGlobals()->getRemoteAddress());
46-
Assert::same('a23-75-45-200.deploy.static.akamaitechnologies.com', @$factory->fromGlobals()->getRemoteHost()); // deprecated
46+
Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated
4747

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

6363
$factory->setProxy('127.0.0.3');
6464
Assert::same('2001:db8:cafe::17', $factory->fromGlobals()->getRemoteAddress());
65-
Assert::same('2001:db8:cafe::17', @$factory->fromGlobals()->getRemoteHost()); // deprecated
65+
Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated
6666

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

8080
$factory->setProxy('127.0.0.3');
8181
Assert::same('2001:db8:cafe::17', $factory->fromGlobals()->getRemoteAddress());
82-
Assert::same('2001:db8:cafe::17', @$factory->fromGlobals()->getRemoteHost()); // deprecated
82+
Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated
8383

8484
$url = $factory->fromGlobals()->getUrl();
8585
Assert::same(47832, $url->getPort());

tests/Http/RequestFactory.proxy.x-forwarded.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test('', function () {
2727

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

3232
$url = $factory->fromGlobals()->getUrl();
3333
Assert::same('otherhost', $url->getHost());
@@ -44,11 +44,11 @@ test('', function () {
4444
$factory = new RequestFactory;
4545
$factory->setProxy('10.0.0.0/24');
4646
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
47-
Assert::same('172.16.0.1', @$factory->fromGlobals()->getRemoteHost()); // deprecated
47+
Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated
4848
Assert::same('real', $factory->fromGlobals()->getUrl()->getHost());
4949

5050
$factory->setProxy(['10.0.0.1', '10.0.0.2']);
5151
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
52-
Assert::same('172.16.0.1', @$factory->fromGlobals()->getRemoteHost()); // deprecated
52+
Assert::null(@$factory->fromGlobals()->getRemoteHost()); // deprecated
5353
Assert::same('real', $factory->fromGlobals()->getUrl()->getHost());
5454
});

0 commit comments

Comments
 (0)