瀏覽代碼

Handle null values for RemoteIpAddress and LocalIpAddress in websocket requests

These values are null when creating fake web requests as part of integration tests
Mark Monteiro 5 年之前
父節點
當前提交
3cf2fce983
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs

+ 7 - 1
Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs

@@ -62,6 +62,9 @@ namespace Emby.Server.Implementations.SocketSharp
                     if (!IPAddress.TryParse(GetHeader(CustomHeaderNames.XRealIP), out ip))
                     {
                         ip = Request.HttpContext.Connection.RemoteIpAddress;
+
+                        // Default to the loopback address if no RemoteIpAddress is specified (i.e. during integration tests)
+                        ip ??= IPAddress.Loopback;
                     }
                 }
 
@@ -89,7 +92,10 @@ namespace Emby.Server.Implementations.SocketSharp
 
         public IQueryCollection QueryString => Request.Query;
 
-        public bool IsLocal => Request.HttpContext.Connection.LocalIpAddress.Equals(Request.HttpContext.Connection.RemoteIpAddress);
+        public bool IsLocal =>
+            (Request.HttpContext.Connection.LocalIpAddress == null
+            && Request.HttpContext.Connection.RemoteIpAddress == null)
+            || Request.HttpContext.Connection.LocalIpAddress.Equals(Request.HttpContext.Connection.RemoteIpAddress);
 
         public string HttpMethod => Request.Method;