Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@ericcholis

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.

@ericcholis ericcholis 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.
1caf8a0
@nateabele nateabele merged commit d8625c5 into UnionOfRAD:dev

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 12, 2012
  1. @ericcholis

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

    ericcholis authored
    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.
This page is out of date. Refresh to see the latest.
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'
)));
Something went wrong with that request. Please try again.