request-ip
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -5,6 +5,13 @@ # Change Log | ||
[Full Changelog](https://github.com/pbojinov/request-ip/compare/1.1.4...HEAD) | ||
[Full Changelog](https://github.com/pbojinov/request-ip/compare/1.2.0...HEAD) | ||
**Merged pull requests:** | ||
- introduce a built-in default implementation for a connect-middleware [\#12](https://github.com/pbojinov/request-ip/pull/12) ([osherx](https://github.com/osherx)) | ||
## [1.2.0](https://github.com/pbojinov/request-ip/tree/1.2.0) (2016-01-27) | ||
[Full Changelog](https://github.com/pbojinov/request-ip/compare/1.1.4...1.2.0) | ||
**Merged pull requests:** | ||
- Got it working in a case that was returning null [\#11](https://github.com/pbojinov/request-ip/pull/11) ([andfaulkner](https://github.com/andfaulkner)) | ||
@@ -11,0 +18,0 @@ |
58
index.js
@@ -25,10 +25,17 @@ /** | ||
// most likely because our app will be behind a [reverse] proxy or load balancer | ||
var clientIp = req.headers['x-client-ip'], | ||
forwardedForAlt = req.headers['x-forwarded-for'], | ||
realIp = req.headers['x-real-ip'], | ||
// more obsure ones below | ||
clusterClientIp = req.headers['x-cluster-client-ip'], | ||
forwardedAlt = req.headers['x-forwarded'], | ||
forwardedFor = req.headers['forwarded-for'], | ||
forwarded = req.headers['forwarded']; | ||
var clientIp = req.headers['x-client-ip']; | ||
var forwardedForAlt = req.headers['x-forwarded-for']; | ||
var realIp = req.headers['x-real-ip']; | ||
// more obsure ones below | ||
var clusterClientIp = req.headers['x-cluster-client-ip']; | ||
var forwardedAlt = req.headers['x-forwarded']; | ||
var forwardedFor = req.headers['forwarded-for']; | ||
var forwarded = req.headers['forwarded']; | ||
// remote address check | ||
var reqConnectionRemoteAddress = req.connection ? req.connection.remoteAddress : null; | ||
var reqSocketRemoteAddress = req.socket ? req.socket.remoteAddress : null; | ||
var reqConnectionSocketRemoteAddress = (req.connection && req.connection.socket) ? req.connection.socket.remoteAddress : null; | ||
var reqInfoRemoteAddress = req.info ? req.info.remoteAddress : null; | ||
@@ -81,24 +88,21 @@ // x-client-ip | ||
// fallback to something | ||
if (!ipAddress) { | ||
// ensure getting client IP address still works in development environment | ||
// if despite all this we do not find ip, then it returns null | ||
try { | ||
ipAddress = req.connection.remoteAddress || | ||
req.socket.remoteAddress || | ||
req.connection.socket.remoteAddress || // for https | ||
null; | ||
} catch(e) { | ||
ipAddress = null; | ||
} | ||
// remote address checks | ||
else if (reqConnectionRemoteAddress) { | ||
ipAddress = reqConnectionRemoteAddress; | ||
} | ||
// final attempt to get IP address, via info object within request. | ||
// if despite all this we do not find ip, then it returns null. | ||
if (!ipAddress) { | ||
if (typeof req.info !== 'undefined'){ | ||
ipAddress = req.info.remoteAddress || null; | ||
} | ||
else if (reqSocketRemoteAddress) { | ||
ipAddress = reqSocketRemoteAddress | ||
} | ||
else if (reqConnectionSocketRemoteAddress) { | ||
ipAddress = reqConnectionSocketRemoteAddress | ||
} | ||
else if (reqInfoRemoteAddress) { | ||
ipAddress = reqInfoRemoteAddress | ||
} | ||
// return null if we cannot find an address | ||
else { | ||
ipAddress = null; | ||
} | ||
return ipAddress; | ||
@@ -105,0 +109,0 @@ } |
{ | ||
"name": "request-ip", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A small node.js module to retrieve the request's IP address", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -88,2 +88,4 @@ #request-ip | ||
To generate a new changelog, run [github_changelog_generator](https://github.com/skywinder/github-changelog-generator). | ||
## Contributors | ||
@@ -90,0 +92,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21953
375
97