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

Client IP address #35

Closed
achingbrain opened this issue Jun 22, 2015 · 7 comments · Fixed by #36
Closed

Client IP address #35

achingbrain opened this issue Jun 22, 2015 · 7 comments · Fixed by #36
Assignees
Labels
Milestone

Comments

@achingbrain
Copy link

@achingbrain achingbrain commented Jun 22, 2015

Is it possible to specify what the IP address of the client making the fake request should appear to be?

E.g. so we can control what request.info.remoteAddress is populated with.

@mtharrison mtharrison added the question label Jun 22, 2015
@mtharrison

This comment has been minimized.

Copy link
Member

@mtharrison mtharrison commented Jun 22, 2015

No, it's not possible to use Shot for that at the moment. The request that is passed to the listener isn't associated with a socket connection so hapi's (assumed your using hapi because you said request.info.remoteAddress) Request object has a empty string set as the remoteAddress:

https://github.com/hapijs/hapi/blob/master/lib/request.js#L114

@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Jun 22, 2015

@achingbrain are you looking to simulate an ip address or try to get the current machine address? If you can provide a use case for the former, I could support that.

@achingbrain

This comment has been minimized.

Copy link
Author

@achingbrain achingbrain commented Jun 23, 2015

@hueniverse I'm trying to simulate an IP address.

Our use case is that we have a Hapi API that contacts a downstream system. The downstream system requires that we send the IP address of the client using our API as a header for auditing purposes. We have sort-of-integration tests that use nock to stub the downstream system and server.inject to simulate incoming requests.

Since we can't affect the value of request.info.remoteAddress we can't assert that the correct IP is being sent.

@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Jun 23, 2015

@achingbrain would you like to try and propose a code change via PR so we can review and consider?

@mtharrison

This comment has been minimized.

Copy link
Member

@mtharrison mtharrison commented Jun 23, 2015

@achingbrain if you do make a PR, one thing to note is that hapi will bail out of processing a request if it has a connection property and the server isn't started:

https://github.com/hapijs/hapi/blob/master/lib/connection.js#L222-L226

So we might require a change over there too? Perhaps we can check for Shot.isInjection(req) or for the presence of the end() method.

@mtharrison

This comment has been minimized.

Copy link
Member

@mtharrison mtharrison commented Aug 4, 2015

Once hapi is updated to shot v1.6.0 this feature will be available through server.inject() with the remoteAddress option.

@mtharrison mtharrison added feature request and removed feature labels Aug 4, 2015
@achingbrain

This comment has been minimized.

Copy link
Author

@achingbrain achingbrain commented Aug 4, 2015

That's awesome, thank you so much.

@Marsup Marsup added support feature and removed question labels Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.