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

Populate RemoteIpAddress and RemotePort on HttpContext.Connection #89

Merged
merged 1 commit into from
Apr 26, 2017

Conversation

Marcus-L
Copy link
Contributor

Fixes #22

Allows the AspNetCore application to access the remote client ip/port information via HttpContext.Connection, which works when running locally via dotnet run.

RemoteIpAddress is obtained from the APIGatewayProxyRequest's RequestContext.Identity.SourceIp
RemotePort is obtained from the APIGatewayProxyRequest's Headers["X-Forwarded-Port"]

For example this would allow for a WebAPI Controller to use the remote info:

[HttpGet]
public string GetRemote()
{
    var c = HttpContext.Connection;
    return $"{c.RemoteIpAddress}:{c.RemotePort}";
}

Updated the test input to provide the source IP, did not add the header "X-Forwarded-Port" in case a better place to get port information from is known by the maintainer.

@normj
Copy link
Member

normj commented Apr 19, 2017

Thanks for the pull request. I have this merged in a local branch. I'm trying to finish off a couple more things first and then I'll do a release with this change and close out this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants