normalize remote ip

This commit is contained in:
Luke Pulverenti 2016-01-19 22:02:26 -05:00
parent f26693c9a3
commit 2e78362db2

View File

@ -136,11 +136,27 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
{
return remoteIp ??
(remoteIp = XForwardedFor ??
(XRealIp ??
((request.RemoteEndPoint != null) ? request.RemoteEndPoint.Address.ToString() : null)));
(NormalizeIp(XRealIp) ??
((request.RemoteEndPoint != null) ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null)));
}
}
private string NormalizeIp(string ip)
{
if (!string.IsNullOrWhiteSpace(ip))
{
// Handle ipv4 mapped to ipv6
const string srch = "::ffff:";
var index = ip.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
if (index == 0)
{
ip = ip.Substring(srch.Length);
}
}
return ip;
}
public bool IsSecureConnection
{
get { return request.IsSecureConnection || XForwardedProtocol == "https"; }