فهرست منبع

Clean `WebSocketSharpRequest.PathInfo` (#1212)

* rm useless ResolvePathInfoFromMappedPath method

* rm useless NormalizePathInfo method

* Use request.Path instead of RawUrl

* Removing unused `HandlerFactoryPath` field

* Use an  expression body definition and rm field `pathInfo`

* More (syntactic) sugar

* Who needs blocks in cases ?
Ulysse 6 سال پیش
والد
کامیت
a1d50a6d05
1فایلهای تغییر یافته به همراه1 افزوده شده و 113 حذف شده
  1. 1 113
      Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs

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

@@ -25,8 +25,6 @@ namespace Emby.Server.Implementations.SocketSharp
             this.OperationName = operationName;
             this.OperationName = operationName;
             this.request = httpContext;
             this.request = httpContext;
             this.Response = new WebSocketSharpResponse(logger, response);
             this.Response = new WebSocketSharpResponse(logger, response);
-
-            // HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]);
         }
         }
 
 
         public HttpRequest HttpRequest => request;
         public HttpRequest HttpRequest => request;
@@ -100,7 +98,6 @@ namespace Emby.Server.Implementations.SocketSharp
                 switch (crlf)
                 switch (crlf)
                 {
                 {
                     case 0:
                     case 0:
-                    {
                         if (c == '\r')
                         if (c == '\r')
                         {
                         {
                             crlf = 1;
                             crlf = 1;
@@ -117,10 +114,8 @@ namespace Emby.Server.Implementations.SocketSharp
                         }
                         }
 
 
                         break;
                         break;
-                    }
 
 
                     case 1:
                     case 1:
-                    {
                         if (c == '\n')
                         if (c == '\n')
                         {
                         {
                             crlf = 2;
                             crlf = 2;
@@ -128,10 +123,8 @@ namespace Emby.Server.Implementations.SocketSharp
                         }
                         }
 
 
                         throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
                         throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
-                    }
 
 
                     case 2:
                     case 2:
-                    {
                         if (c == ' ' || c == '\t')
                         if (c == ' ' || c == '\t')
                         {
                         {
                             crlf = 0;
                             crlf = 0;
@@ -139,7 +132,6 @@ namespace Emby.Server.Implementations.SocketSharp
                         }
                         }
 
 
                         throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
                         throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
-                    }
                 }
                 }
             }
             }
 
 
@@ -312,97 +304,7 @@ namespace Emby.Server.Implementations.SocketSharp
             return pos == -1 ? strVal : strVal.Slice(0, pos);
             return pos == -1 ? strVal : strVal.Slice(0, pos);
         }
         }
 
 
-        public static string HandlerFactoryPath;
-
-        private string pathInfo;
-        public string PathInfo
-        {
-            get
-            {
-                if (this.pathInfo == null)
-                {
-                    var mode = HandlerFactoryPath;
-
-                    var pos = RawUrl.IndexOf("?", StringComparison.Ordinal);
-                    if (pos != -1)
-                    {
-                        var path = RawUrl.Substring(0, pos);
-                        this.pathInfo = GetPathInfo(
-                            path,
-                            mode,
-                            mode ?? string.Empty);
-                    }
-                    else
-                    {
-                        this.pathInfo = RawUrl;
-                    }
-
-                    this.pathInfo = WebUtility.UrlDecode(pathInfo);
-                    this.pathInfo = NormalizePathInfo(pathInfo, mode).ToString();
-                }
-
-                return this.pathInfo;
-            }
-        }
-
-        private static string GetPathInfo(string fullPath, string mode, string appPath)
-        {
-            var pathInfo = ResolvePathInfoFromMappedPath(fullPath, mode);
-            if (!string.IsNullOrEmpty(pathInfo))
-            {
-                return pathInfo;
-            }
-
-            // Wildcard mode relies on this to work out the handlerPath
-            pathInfo = ResolvePathInfoFromMappedPath(fullPath, appPath);
-            if (!string.IsNullOrEmpty(pathInfo))
-            {
-                return pathInfo;
-            }
-
-            return fullPath;
-        }
-
-        private static string ResolvePathInfoFromMappedPath(string fullPath, string mappedPathRoot)
-        {
-            if (mappedPathRoot == null)
-            {
-                return null;
-            }
-
-            var sbPathInfo = new StringBuilder();
-            var fullPathParts = fullPath.Split('/');
-            var mappedPathRootParts = mappedPathRoot.Split('/');
-            var fullPathIndexOffset = mappedPathRootParts.Length - 1;
-            var pathRootFound = false;
-
-            for (var fullPathIndex = 0; fullPathIndex < fullPathParts.Length; fullPathIndex++)
-            {
-                if (pathRootFound)
-                {
-                    sbPathInfo.Append("/" + fullPathParts[fullPathIndex]);
-                }
-                else if (fullPathIndex - fullPathIndexOffset >= 0)
-                {
-                    pathRootFound = true;
-                    for (var mappedPathRootIndex = 0; mappedPathRootIndex < mappedPathRootParts.Length; mappedPathRootIndex++)
-                    {
-                        if (!string.Equals(fullPathParts[fullPathIndex - fullPathIndexOffset + mappedPathRootIndex], mappedPathRootParts[mappedPathRootIndex], StringComparison.OrdinalIgnoreCase))
-                        {
-                            pathRootFound = false;
-                            break;
-                        }
-                    }
-                }
-            }
-
-            if (!pathRootFound)
-            {
-                return null;
-            }
-
-            return sbPathInfo.Length > 1 ? sbPathInfo.ToString().TrimEnd('/') : "/";
-        }
+        public string PathInfo => this.request.Path.Value;
 
 
         public string UserAgent => request.Headers[HeaderNames.UserAgent];
         public string UserAgent => request.Headers[HeaderNames.UserAgent];
 
 
@@ -500,19 +402,5 @@ namespace Emby.Server.Implementations.SocketSharp
                 return httpFiles;
                 return httpFiles;
             }
             }
         }
         }
-
-        public static ReadOnlySpan<char> NormalizePathInfo(string pathInfo, string handlerPath)
-        {
-            if (handlerPath != null)
-            {
-                var trimmed = pathInfo.AsSpan().TrimStart('/');
-                if (trimmed.StartsWith(handlerPath.AsSpan(), StringComparison.OrdinalIgnoreCase))
-                {
-                    return trimmed.Slice(handlerPath.Length).ToString().AsSpan();
-                }
-            }
-
-            return pathInfo.AsSpan();
-        }
     }
     }
 }
 }