diff options
| author | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-04-20 13:59:02 -0400 |
|---|---|---|
| committer | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-04-20 13:59:02 -0400 |
| commit | 3cf2fce983fafbe0efbf8fc21ac267186600837d (patch) | |
| tree | 78fd909b20c6e14c3ba9276a77c8bbd7d52ce0f8 | |
| parent | 32ccab32bf49cd87a13aa3e6344a0736c51b0ff7 (diff) | |
Handle null values for RemoteIpAddress and LocalIpAddress in websocket requests
These values are null when creating fake web requests as part of integration tests
| -rw-r--r-- | Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs index 1781df8b5..f27f7eeb8 100644 --- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs +++ b/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; |
