Skip to content

Commit f88f4a5

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

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/Http/Request.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@ public function getRemoteAddress(): ?string
255255
*/
256256
public function getRemoteHost(): ?string
257257
{
258-
if ($this->remoteHost === null && $this->remoteAddress !== null) {
259-
$this->remoteHost = gethostbyaddr($this->remoteAddress);
260-
}
261-
262258
return $this->remoteHost;
263259
}
264260

tests/Http/RequestFactory.proxy.forwarded.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test('forwarded header handling with proxy', 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());
28+
Assert::null($factory->fromGlobals()->getRemoteHost());
2929

3030
$url = $factory->fromGlobals()->getUrl();
3131
Assert::same('http', $url->getScheme());
@@ -43,7 +43,7 @@ test('forwarded header with port numbers', 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());
46+
Assert::null($factory->fromGlobals()->getRemoteHost());
4747

4848
$url = $factory->fromGlobals()->getUrl();
4949
Assert::same(8080, $url->getPort());
@@ -62,7 +62,7 @@ test('IPv6 addresses in Forwarded header', 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());
65+
Assert::null($factory->fromGlobals()->getRemoteHost());
6666

6767
$url = $factory->fromGlobals()->getUrl();
6868
Assert::same('[2001:db8:cafe::18]', $url->getHost());
@@ -79,7 +79,7 @@ test('IPv6 addresses and ports in Forwarded header', 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());
82+
Assert::null($factory->fromGlobals()->getRemoteHost());
8383

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

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test('X-Forwarded headers handling with proxy', 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());
30+
Assert::null($factory->fromGlobals()->getRemoteHost());
3131

3232
$url = $factory->fromGlobals()->getUrl();
3333
Assert::same('otherhost', $url->getHost());
@@ -45,7 +45,7 @@ test('X-Forwarded-Host with port', function () {
4545
$factory = new RequestFactory;
4646
$factory->setProxy('127.0.0.3');
4747
Assert::same('23.75.45.200', $factory->fromGlobals()->getRemoteAddress());
48-
Assert::same('a23-75-45-200.deploy.static.akamaitechnologies.com', $factory->fromGlobals()->getRemoteHost());
48+
Assert::null($factory->fromGlobals()->getRemoteHost());
4949

5050
$url = $factory->fromGlobals()->getUrl();
5151
Assert::same('otherhost', $url->getHost());
@@ -81,15 +81,15 @@ test('multiple proxies in X-Forwarded headers', function () {
8181
$factory = new RequestFactory;
8282
$factory->setProxy('10.0.0.0/24');
8383
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
84-
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteHost());
84+
Assert::null($factory->fromGlobals()->getRemoteHost());
8585

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

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

9494
$url = $factory->fromGlobals()->getUrl();
9595
Assert::same('real', $url->getHost());
@@ -107,7 +107,7 @@ test('X-Forwarded-Host with multiple entries and port', function () {
107107
$factory = new RequestFactory;
108108
$factory->setProxy(['10.0.0.1', '10.0.0.2']);
109109
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteAddress());
110-
Assert::same('172.16.0.1', $factory->fromGlobals()->getRemoteHost());
110+
Assert::null($factory->fromGlobals()->getRemoteHost());
111111

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

0 commit comments

Comments
 (0)