Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remoteAddress may be undefined #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down