-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented RFC 7239 - "Forwarded HTTP Extension" (#94)
* Implemented RFC 7239 - " Forwarded HTTP Extension" handling in RequestFactory * Implemented RFC 7239 - " Forwarded HTTP Extension" handling in RequestFactory * Deleted echo statement * case- insensitive handling of tokens * Proper handle of quoted strings. Will now work with IPv6. Added tests for port and scheme of the URL [Closes #94] * Tests refactoring: - Split test into "x-forwarded" and "forwarded" files for proxy - Added tests for default scheme. - Added tests for every combination of IPv4/IPv6 with and without port for both "host" and "for" headers * Code simplifications * Fixed coding standards for tests
- Loading branch information
1 parent
dff9775
commit 67a7020
Showing
3 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Http\RequestFactory and proxy with "Forwarded" header. | ||
*/ | ||
|
||
use Nette\Http\RequestFactory; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
test(function () { | ||
$_SERVER = [ | ||
'REMOTE_ADDR' => '127.0.0.3', | ||
'REMOTE_HOST' => 'localhost', | ||
'HTTP_FORWARDED' => 'for=23.75.45.200;host=192.168.0.1', | ||
]; | ||
|
||
$factory = new RequestFactory; | ||
$factory->setProxy('127.0.0.1'); | ||
Assert::same('127.0.0.3', $factory->createHttpRequest()->getRemoteAddress()); | ||
Assert::same('localhost', $factory->createHttpRequest()->getRemoteHost()); | ||
|
||
$factory->setProxy('127.0.0.1/8'); | ||
Assert::same('23.75.45.200', $factory->createHttpRequest()->getRemoteAddress()); | ||
Assert::same('192.168.0.1', $factory->createHttpRequest()->getRemoteHost()); | ||
|
||
$url = $factory->createHttpRequest()->getUrl(); | ||
Assert::same('http', $url->getScheme()); | ||
}); | ||
|
||
test(function () { | ||
$_SERVER = [ | ||
'REMOTE_ADDR' => '127.0.0.3', | ||
'REMOTE_HOST' => 'localhost', | ||
'HTTP_FORWARDED' => 'for=23.75.45.200:8080;host=192.168.0.1:8080', | ||
]; | ||
|
||
$factory = new RequestFactory; | ||
|
||
$factory->setProxy('127.0.0.3'); | ||
Assert::same('23.75.45.200', $factory->createHttpRequest()->getRemoteAddress()); | ||
Assert::same('192.168.0.1', $factory->createHttpRequest()->getRemoteHost()); | ||
|
||
$url = $factory->createHttpRequest()->getUrl(); | ||
Assert::same(8080, $url->getPort()); | ||
}); | ||
|
||
|
||
test(function () { | ||
$_SERVER = [ | ||
'REMOTE_ADDR' => '127.0.0.3', | ||
'REMOTE_HOST' => 'localhost', | ||
'HTTP_FORWARDED' => 'for="[2001:db8:cafe::17]";host="[2001:db8:cafe::18]"', | ||
]; | ||
|
||
$factory = new RequestFactory; | ||
|
||
$factory->setProxy('127.0.0.3'); | ||
Assert::same('2001:db8:cafe::17', $factory->createHttpRequest()->getRemoteAddress()); | ||
Assert::same('2001:db8:cafe::18', $factory->createHttpRequest()->getRemoteHost()); | ||
}); | ||
|
||
test(function () { | ||
$_SERVER = [ | ||
'REMOTE_ADDR' => '127.0.0.3', | ||
'REMOTE_HOST' => 'localhost', | ||
'HTTP_FORWARDED' => 'for="[2001:db8:cafe::17]:47831";host="[2001:db8:cafe::18]:47832"', | ||
]; | ||
|
||
$factory = new RequestFactory; | ||
|
||
$factory->setProxy('127.0.0.3'); | ||
Assert::same('2001:db8:cafe::17', $factory->createHttpRequest()->getRemoteAddress()); | ||
Assert::same('2001:db8:cafe::18', $factory->createHttpRequest()->getRemoteHost()); | ||
|
||
$url = $factory->createHttpRequest()->getUrl(); | ||
Assert::same(47832, $url->getPort()); | ||
}); | ||
|
||
|
||
test(function () { | ||
$_SERVER = [ | ||
'REMOTE_ADDR' => '127.0.0.3', | ||
'REMOTE_HOST' => 'localhost', | ||
'HTTP_FORWARDED' => 'for="[2001:db8:cafe::17]:47831" ; host="[2001:db8:cafe::18]:47832" ; scheme=https', | ||
]; | ||
|
||
$factory = new RequestFactory; | ||
$factory->setProxy('127.0.0.3'); | ||
|
||
$url = $factory->createHttpRequest()->getUrl(); | ||
Assert::same('https', $url->getScheme()); | ||
}); |
2 changes: 1 addition & 1 deletion
2
tests/Http/RequestFactory.proxy.phpt → ...ttp/RequestFactory.proxy.x-forwarded.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters