diff --git a/.travis.yml b/.travis.yml index 2b2f440..023682f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ node_js: sudo: false before_install: # Setup Node.js version-specific dependencies - - "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul" + - "test $TRAVIS_NODE_VERSION != '0.6' -a $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" script: - - "test $TRAVIS_NODE_VERSION != '0.6' || npm test" - - "test $TRAVIS_NODE_VERSION = '0.6' || npm run-script test-travis" + - "test $TRAVIS_NODE_VERSION != '0.6' -a $TRAVIS_NODE_VERSION != '0.8' || npm test" + - "test $TRAVIS_NODE_VERSION = '0.6' -o $TRAVIS_NODE_VERSION = '0.8' || npm run-script test-travis" after_script: - - "test $TRAVIS_NODE_VERSION != '0.6' && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" + - "test $TRAVIS_NODE_VERSION != '0.6' -a $TRAVIS_NODE_VERSION != '0.8' && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" diff --git a/index.js b/index.js index 234f0f7..0d9f4c5 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ function forwarded(req) { .filter(Boolean) .reverse() var socketAddr = req.connection.remoteAddress + if (!socketAddr) return proxyAddrs; var addrs = [socketAddr].concat(proxyAddrs) // return all addresses diff --git a/test/test.js b/test/test.js index f088791..5899569 100644 --- a/test/test.js +++ b/test/test.js @@ -26,6 +26,13 @@ describe('forwarded(req)', function () { }) assert.deepEqual(forwarded(req), ['127.0.0.1', '10.0.0.1', '10.0.0.2']) }) + + it('should parse headers with disconnected client', function () { + var req = createReq(undefined, { + 'x-forwarded-for': '10.0.0.2,, 10.0.0.1' + }) + assert.deepEqual(forwarded(req), ['10.0.0.1', '10.0.0.2']) + }) }) function createReq(socketAddr, headers) {