request-ip
Advanced tools
Comparing version 1.0.0 to 1.1.0
49
index.js
/** | ||
* Author: petar bojinov - @pbojinov | ||
* Date: 01/16/15 | ||
* Date: 04/03/15 | ||
*/ | ||
'use strict'; | ||
/** | ||
@@ -24,4 +26,9 @@ * Get client IP address | ||
var clientIp = req.headers['x-client-ip'], | ||
forwardedIpsStr = req.headers['x-forwarded-for'], | ||
altForwardedIp = req.headers['x-real-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']; | ||
@@ -34,3 +41,3 @@ // x-client-ip | ||
// x-forwarded-for | ||
else if (forwardedIpsStr) { | ||
else if (forwardedForAlt) { | ||
// x-forwarded-for header is more common | ||
@@ -40,13 +47,37 @@ // it may return multiple IP addresses in the format: | ||
// we pick the first one | ||
var forwardedIps = forwardedIpsStr.split(','); | ||
var forwardedIps = forwardedForAlt.split(','); | ||
ipAddress = forwardedIps[0]; | ||
} | ||
// x-real-ip | ||
else if (altForwardedIp) { | ||
// x-real-ip | ||
// (default nginx proxy/fcgi) | ||
else if (realIp) { | ||
// alternative to x-forwarded-for | ||
// used by some proxies | ||
ipAddress = altForwardedIp; | ||
ipAddress = realIp; | ||
} | ||
// x-cluster-client-ip | ||
// (Rackspace LB and Riverbed's Stingray) | ||
// http://www.rackspace.com/knowledge_center/article/controlling-access-to-linux-cloud-sites-based-on-the-client-ip-address | ||
// https://splash.riverbed.com/docs/DOC-1926 | ||
else if (clusterClientIp) { | ||
ipAddress = clusterClientIp; | ||
} | ||
// x-forwarded | ||
else if (forwardedAlt) { | ||
ipAddress = forwardedAlt; | ||
} | ||
// forwarded-for | ||
else if (forwardedFor) { | ||
ipAddress = forwardedFor; | ||
} | ||
// forwarded | ||
else if (forwarded) { | ||
ipAddress = forwarded; | ||
} | ||
// fallback to something | ||
@@ -57,3 +88,3 @@ if (!ipAddress) { | ||
req.socket.remoteAddress || | ||
req.connection.socket.remoteAddress; | ||
req.connection.socket.remoteAddress; // for https | ||
} | ||
@@ -60,0 +91,0 @@ |
{ | ||
"name": "request-ip", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A small node.js module to retrieve the request's IP address", | ||
@@ -10,6 +10,9 @@ "main": "index.js", | ||
}, | ||
"scripts": { | ||
"test": "node test/index.js | tap-spec" | ||
}, | ||
"keywords": [ | ||
"ip", | ||
"address", | ||
"client", | ||
"client", | ||
"header", | ||
@@ -28,3 +31,8 @@ "X-Real-IP", | ||
}, | ||
"homepage": "https://github.com/pbojinov/request-ip" | ||
"homepage": "https://github.com/pbojinov/request-ip", | ||
"devDependencies": { | ||
"request": "^2.54.0", | ||
"tap-spec": "^3.0.0", | ||
"tape": "^4.0.0" | ||
} | ||
} |
@@ -8,3 +8,2 @@ request-ip | ||
## Installation | ||
@@ -14,3 +13,3 @@ | ||
![](https://nodei.co/npm/request-ip.png?downloads=true) | ||
![](https://nodei.co/npm/request-ip.png?downloads=true&cacheBust=1) | ||
@@ -38,5 +37,7 @@ ## Getting Started | ||
3. `X-Real-IP` | ||
4. `req.connection.remoteAddress` | ||
5. `req.socket.remoteAddress` | ||
6. `req.connection.socket.remoteAddress` | ||
5. `X-Cluster-Client-IP` | ||
6. Permuations of #2 such as: `X-Forwarded`, `Forwarded-For` and `Forwarded` | ||
7. `req.connection.remoteAddress` | ||
8. `req.socket.remoteAddress` | ||
9. `req.connection.socket.remoteAddress` | ||
@@ -51,4 +52,23 @@ ## Use Case | ||
## Running the Tests | ||
Make sure you have the necessary dependencies: | ||
``` | ||
npm install | ||
``` | ||
Run the integration tests | ||
``` | ||
npm test | ||
``` | ||
## Release Notes | ||
1.1.0 | ||
* add support for X-Cluster-Client-IP, X-Forwarded, Forwarded-For, Forwarded | ||
* add tests | ||
1.0.0 | ||
@@ -55,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
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
13619
6
289
94
3
2