@@ -15,8 +15,8 @@ test(function () {
15
15
$ _SERVER = [
16
16
'REMOTE_ADDR ' => '127.0.0.3 ' ,
17
17
'REMOTE_HOST ' => 'localhost ' ,
18
- 'HTTP_X_FORWARDED_FOR ' => '23.75.345 .200, 10.0.0.1 ' ,
19
- 'HTTP_X_FORWARDED_HOST ' => 'otherhost, anotherhost ' ,
18
+ 'HTTP_X_FORWARDED_FOR ' => '23.75.45 .200 ' ,
19
+ 'HTTP_X_FORWARDED_HOST ' => 'otherhost ' ,
20
20
];
21
21
22
22
$ factory = new RequestFactory ;
@@ -25,6 +25,24 @@ test(function () {
25
25
Assert::same ('localhost ' , $ factory ->createHttpRequest ()->getRemoteHost ());
26
26
27
27
$ factory ->setProxy ('127.0.0.1/8 ' );
28
- Assert::same ('23.75.345 .200 ' , $ factory ->createHttpRequest ()->getRemoteAddress ());
28
+ Assert::same ('23.75.45 .200 ' , $ factory ->createHttpRequest ()->getRemoteAddress ());
29
29
Assert::same ('otherhost ' , $ factory ->createHttpRequest ()->getRemoteHost ());
30
30
});
31
+
32
+ test (function () {
33
+ $ _SERVER = [
34
+ 'REMOTE_ADDR ' => '10.0.0.2 ' , //proxy2
35
+ 'REMOTE_HOST ' => 'proxy2 ' ,
36
+ 'HTTP_X_FORWARDED_FOR ' => '123.123.123.123, 172.16.0.1, 10.0.0.1 ' ,
37
+ 'HTTP_X_FORWARDED_HOST ' => 'fake, real, proxy1 ' ,
38
+ ];
39
+
40
+ $ factory = new RequestFactory ;
41
+ $ factory ->setProxy ('10.0.0.0/24 ' );
42
+ Assert::same ('172.16.0.1 ' , $ factory ->createHttpRequest ()->getRemoteAddress ());
43
+ Assert::same ('real ' , $ factory ->createHttpRequest ()->getRemoteHost ());
44
+
45
+ $ factory ->setProxy (['10.0.0.1 ' , '10.0.0.2 ' ]);
46
+ Assert::same ('172.16.0.1 ' , $ factory ->createHttpRequest ()->getRemoteAddress ());
47
+ Assert::same ('real ' , $ factory ->createHttpRequest ()->getRemoteHost ());
48
+ });
0 commit comments