Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for X-Real-Ip header (from nginx)

Some nginx proxy_pass configurations have the remote address set to the HTTP_X_REAL_IP header. See http://wiki.nginx.org/HttpProxyModule for details.
  • Loading branch information...
commit 1caf8a0a0c92da07dfec0d748db06bb98dc51bf8 1 parent dc210f6
@ericcholis ericcholis authored
Showing with 7 additions and 1 deletion.
  1. +1 −1  action/Request.php
  2. +6 −0 tests/cases/action/RequestTest.php
View
2  action/Request.php
@@ -246,7 +246,7 @@ public function env($key) {
$this->_env[$key] = $val;
if ($key == 'REMOTE_ADDR') {
- foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_PC_REMOTE_ADDR') as $altKey) {
+ foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_PC_REMOTE_ADDR', 'HTTP_X_REAL_IP') as $altKey) {
if ($addr = $this->env($altKey)) {
$val = $addr;
break;
View
6 tests/cases/action/RequestTest.php
@@ -137,6 +137,12 @@ public function testRemoteAddr() {
$request = new Request(array('env' => array(
'REMOTE_ADDR' => '123.456.789.000',
+ 'HTTP_X_REAL_IP' => '111.222.333.444'
+ )));
+ $this->assertEqual('111.222.333.444', $request->env('REMOTE_ADDR'));
+
+ $request = new Request(array('env' => array(
+ 'REMOTE_ADDR' => '123.456.789.000',
'HTTP_X_FORWARDED_FOR' => '111.222.333.444',
'HTTP_PC_REMOTE_ADDR' => '222.333.444.555'
)));
Please sign in to comment.
Something went wrong with that request. Please try again.