diff --git a/Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs b/Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs
index 455fcf26a..2bda4d328 100644
--- a/Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs
+++ b/Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Net;
using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
@@ -214,13 +215,14 @@ protected string ErrorReport(Exception e)
}
///
- /// Convert the JSON document received from API Gateway in the ASP.NET Core IHttpRequestFeature object.
- /// IHttpRequestFeature is then passed into IHttpApplication to create the ASP.NET Core request objects.
+ /// Convert the JSON document received from API Gateway into the InvokeFeatures object.
+ /// InvokeFeatures is then passed into IHttpApplication to create the ASP.NET Core request objects.
///
- ///
+ ///
///
- protected void MarshallRequest(IHttpRequestFeature requestFeatures, APIGatewayProxyRequest apiGatewayRequest)
+ protected void MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest)
{
+ var requestFeatures = (IHttpRequestFeature)features;
requestFeatures.Scheme = "https";
requestFeatures.Path = apiGatewayRequest.Path;
requestFeatures.Method = apiGatewayRequest.HttpMethod;
@@ -273,6 +275,13 @@ protected void MarshallRequest(IHttpRequestFeature requestFeatures, APIGatewayPr
}
requestFeatures.Body = new MemoryStream(binaryBody);
}
+ // set up connection features
+ var connectionFeatures = (IHttpConnectionFeature)features;
+ connectionFeatures.RemoteIpAddress = IPAddress.Parse(apiGatewayRequest.RequestContext.Identity.SourceIp);
+ if (apiGatewayRequest.Headers?.ContainsKey("X-Forwarded-Port") == true)
+ {
+ connectionFeatures.RemotePort = int.Parse(apiGatewayRequest.Headers["X-Forwarded-Port"]);
+ }
}
///
diff --git a/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs b/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs
index a2ab35833..017b91237 100644
--- a/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs
+++ b/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
@@ -14,11 +15,11 @@ namespace Amazon.Lambda.AspNetCoreServer.Internal
{
public class InvokeFeatures : IFeatureCollection,
IHttpRequestFeature,
- IHttpResponseFeature
+ IHttpResponseFeature,
+ IHttpConnectionFeature
/*
,
IHttpUpgradeFeature,
- IHttpConnectionFeature,
IHttpRequestLifetimeFeature*/
{
@@ -26,6 +27,7 @@ public InvokeFeatures()
{
_features[typeof(IHttpRequestFeature)] = this;
_features[typeof(IHttpResponseFeature)] = this;
+ _features[typeof(IHttpConnectionFeature)] = this;
}
#region IFeatureCollection
@@ -146,5 +148,18 @@ void IHttpResponseFeature.OnCompleted(Func