Permalink
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...
1 parent dc210f6 commit 1caf8a0a0c92da07dfec0d748db06bb98dc51bf8 @ericcholis committed Nov 12, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 action/Request.php
  2. +6 −0 tests/cases/action/RequestTest.php
View
@@ -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;
@@ -135,6 +135,12 @@ public function testRemoteAddr() {
)));
$this->assertEqual('222.333.444.555', $request->env('REMOTE_ADDR'));
+ $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',

0 comments on commit 1caf8a0

Please sign in to comment.