mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
Replace custom ip "normalization" by methods from IPAddress
This commit is contained in:
parent
a6e1b23eb0
commit
56d1050bac
1 changed files with 10 additions and 11 deletions
|
@ -62,10 +62,10 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||||
temp = CheckBadChars(GetHeader(HeaderNames.XRealIP).AsSpan());
|
temp = CheckBadChars(GetHeader(HeaderNames.XRealIP).AsSpan());
|
||||||
if (temp.Length != 0)
|
if (temp.Length != 0)
|
||||||
{
|
{
|
||||||
return remoteIp = NormalizeIp(temp).ToString();
|
return remoteIp = NormalizeIp(temp.ToString()).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return remoteIp = NormalizeIp(request.HttpContext.Connection.RemoteIpAddress.ToString().AsSpan()).ToString();
|
return remoteIp = NormalizeIp(request.HttpContext.Connection.RemoteIpAddress).ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,22 +137,21 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReadOnlySpan<char> NormalizeIp(ReadOnlySpan<char> ip)
|
private IPAddress NormalizeIp(IPAddress ip)
|
||||||
{
|
{
|
||||||
if (ip.Length != 0 && !ip.IsWhiteSpace())
|
if (ip.IsIPv4MappedToIPv6)
|
||||||
{
|
{
|
||||||
// Handle ipv4 mapped to ipv6
|
return ip.MapToIPv4();
|
||||||
const string srch = "::ffff:";
|
|
||||||
var index = ip.IndexOf(srch.AsSpan(), StringComparison.OrdinalIgnoreCase);
|
|
||||||
if (index == 0)
|
|
||||||
{
|
|
||||||
ip = ip.Slice(srch.Length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IPAddress NormalizeIp(string sip)
|
||||||
|
{
|
||||||
|
return NormalizeIp(IPAddress.Parse(sip));
|
||||||
|
}
|
||||||
|
|
||||||
public string[] AcceptTypes => request.Headers.GetCommaSeparatedValues(HeaderNames.Accept);
|
public string[] AcceptTypes => request.Headers.GetCommaSeparatedValues(HeaderNames.Accept);
|
||||||
|
|
||||||
private Dictionary<string, object> items;
|
private Dictionary<string, object> items;
|
||||||
|
|
Loading…
Reference in a new issue