Permalink
Browse files

Added `req.ip`

  • Loading branch information...
1 parent b694ba2 commit d84d0b69effd3d5a549dc502b5a2d8ee1f1a0b7d @tj tj committed May 30, 2012
Showing with 15 additions and 2 deletions.
  1. +13 −0 lib/request.js
  2. +2 −2 test/req.ips.js
View
@@ -325,6 +325,19 @@ req.__defineGetter__('secure', function(){
return 'https' == this.protocol;
});
+/**
+ * Return the remote address, or when
+ * "trust proxy" is `true` return
+ * the upstream addr.
+ *
+ * @return {String}
+ * @api public
+ */
+
+req.__defineGetter__('ip', function(){
+ return this.ips[0] || this.connection.remoteAddress;
+});
+
/**
* When "trust proxy" is `true`, parse
* the "X-Forwarded-For" ip address list.
View
@@ -5,7 +5,7 @@ var express = require('../')
describe('req', function(){
describe('.ips', function(){
describe('when X-Forwarded-For is present', function(){
- describe('when "trust proxies" is enabled', function(){
+ describe('when "trust proxy" is enabled', function(){
it('should return an array of the specified addresses', function(done){
var app = express();
@@ -22,7 +22,7 @@ describe('req', function(){
})
})
- describe('when "trust proxies" is disabled', function(){
+ describe('when "trust proxy" is disabled', function(){
it('should return an empty array', function(done){
var app = express();

0 comments on commit d84d0b6

Please sign in to comment.