Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 40 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisesprovided option to use x-forwarded-for as remote address [updated] #226
Conversation
This comment has been minimized.
This comment has been minimized.
Would there ever be a time where you wouldn't want this? If not, rather than adding another option, why not just always log this value and if that header isn't set, it'll be |
This comment has been minimized.
This comment has been minimized.
If x-forwarde-for is not in the header remoteAddress will fall back to request.info.remoteAddress. Also I would love to be able get x-forwarde-for logged without adding another option. Could you clarify "always log this value"? Can it be done without modifying the code? Thanks. Sent from my iPhone
|
@@ -228,7 +229,7 @@ internals.Monitor.prototype._requestHandler = function (request) { | |||
path: request.path, | |||
query: request.query, | |||
source: { | |||
remoteAddress: request.info.remoteAddress, | |||
remoteAddress: this.settings.xforward && req.headers['x-forwarded-for'] || request.info.remoteAddress, | |||
userAgent: req.headers['user-agent'], |
This comment has been minimized.
This comment has been minimized.
arb
Oct 31, 2014
Contributor
Under remoteAddress
, you can add forwardedFor
and set it to req.headers['x-forwarded-for']
Then you don't need the extra option.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Can you rebase this branch? 7 commits for a single line change is a bit much |
This comment has been minimized.
This comment has been minimized.
Agreed :) I just did. See if you can merge now. Thanks for being so patient with a complete PR newbie. |
This comment has been minimized.
This comment has been minimized.
Still have 7 commits. At this point it would probably be easier to just start a new local branch and make the changes there since it's only one line. |
This comment has been minimized.
This comment has been minimized.
Learned how to squash. How about now? Thanks. |
This comment has been minimized.
This comment has been minimized.
Can you please add or update a test showing that this works? Both in cases where this header is set and unset? |
This comment has been minimized.
This comment has been minimized.
UPDATE actually before we make this change, have you tried setting |
This comment has been minimized.
This comment has been minimized.
Yup you nailed it. Should've tried that option first. Will close the PR soon. |
midnightcodr commentedOct 25, 2014
Providing the option to use X-Forwarded-For as remote client's ip address can be very useful when hapi serves behind nginx or a load balancing web server. It makes more sense to record the 'true' remote ip instead of the proxy server's ip in that kind of scenario.