From c8904fd80ca0bb08ef4784ff965ec66c226fb03d Mon Sep 17 00:00:00 2001 From: sta Date: Mon, 14 Jan 2019 22:34:02 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Net/HttpUtility.cs | 45 ++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/websocket-sharp/Net/HttpUtility.cs b/websocket-sharp/Net/HttpUtility.cs index f427da7b..c6a35ff5 100644 --- a/websocket-sharp/Net/HttpUtility.cs +++ b/websocket-sharp/Net/HttpUtility.cs @@ -694,21 +694,37 @@ namespace WebSocketSharp.Net #region Internal Methods internal static Uri CreateRequestUrl ( - string requestUri, string host, bool websocketRequest, bool secure) + string requestUri, string host, bool websocketRequest, bool secure + ) { - if (requestUri == null || requestUri.Length == 0 || host == null || host.Length == 0) + if (requestUri == null) + return null; + + if (host == null) + return null; + + if (requestUri.Length == 0) + return null; + + if (host.Length == 0) return null; string schm = null; string path = null; + if (requestUri.StartsWith ("/")) { path = requestUri; } else if (requestUri.MaybeUri ()) { Uri uri; - var valid = Uri.TryCreate (requestUri, UriKind.Absolute, out uri) && - (((schm = uri.Scheme).StartsWith ("http") && !websocketRequest) || - (schm.StartsWith ("ws") && websocketRequest)); + var valid = Uri.TryCreate (requestUri, UriKind.Absolute, out uri) + && ( + ( + (schm = uri.Scheme).StartsWith ("http") + && !websocketRequest + ) + || (schm.StartsWith ("ws") && websocketRequest) + ); if (!valid) return null; @@ -723,20 +739,25 @@ namespace WebSocketSharp.Net host = requestUri; } - if (schm == null) - schm = (websocketRequest ? "ws" : "http") + (secure ? "s" : String.Empty); + if (schm == null) { + schm = (websocketRequest ? "ws" : "http") + + (secure ? "s" : String.Empty); + } var colon = host.IndexOf (':'); - if (colon == -1) - host = String.Format ("{0}:{1}", host, schm == "http" || schm == "ws" ? 80 : 443); + if (colon == -1) { + host = String.Format ( + "{0}:{1}", host, schm == "http" || schm == "ws" ? 80 : 443 + ); + } var url = String.Format ("{0}://{1}{2}", schm, host, path); - Uri res; - if (!Uri.TryCreate (url, UriKind.Absolute, out res)) + Uri ret; + if (!Uri.TryCreate (url, UriKind.Absolute, out ret)) return null; - return res; + return ret; } internal static IPrincipal CreateUser (