[Modify] Polish it
This commit is contained in:
parent
08f15dcee3
commit
c8904fd80c
@ -694,21 +694,37 @@ namespace WebSocketSharp.Net
|
|||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
|
|
||||||
internal static Uri CreateRequestUrl (
|
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;
|
return null;
|
||||||
|
|
||||||
string schm = null;
|
string schm = null;
|
||||||
string path = null;
|
string path = null;
|
||||||
|
|
||||||
if (requestUri.StartsWith ("/")) {
|
if (requestUri.StartsWith ("/")) {
|
||||||
path = requestUri;
|
path = requestUri;
|
||||||
}
|
}
|
||||||
else if (requestUri.MaybeUri ()) {
|
else if (requestUri.MaybeUri ()) {
|
||||||
Uri uri;
|
Uri uri;
|
||||||
var valid = Uri.TryCreate (requestUri, UriKind.Absolute, out uri) &&
|
var valid = Uri.TryCreate (requestUri, UriKind.Absolute, out uri)
|
||||||
(((schm = uri.Scheme).StartsWith ("http") && !websocketRequest) ||
|
&& (
|
||||||
(schm.StartsWith ("ws") && websocketRequest));
|
(
|
||||||
|
(schm = uri.Scheme).StartsWith ("http")
|
||||||
|
&& !websocketRequest
|
||||||
|
)
|
||||||
|
|| (schm.StartsWith ("ws") && websocketRequest)
|
||||||
|
);
|
||||||
|
|
||||||
if (!valid)
|
if (!valid)
|
||||||
return null;
|
return null;
|
||||||
@ -723,20 +739,25 @@ namespace WebSocketSharp.Net
|
|||||||
host = requestUri;
|
host = requestUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schm == null)
|
if (schm == null) {
|
||||||
schm = (websocketRequest ? "ws" : "http") + (secure ? "s" : String.Empty);
|
schm = (websocketRequest ? "ws" : "http")
|
||||||
|
+ (secure ? "s" : String.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
var colon = host.IndexOf (':');
|
var colon = host.IndexOf (':');
|
||||||
if (colon == -1)
|
if (colon == -1) {
|
||||||
host = String.Format ("{0}:{1}", host, schm == "http" || schm == "ws" ? 80 : 443);
|
host = String.Format (
|
||||||
|
"{0}:{1}", host, schm == "http" || schm == "ws" ? 80 : 443
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var url = String.Format ("{0}://{1}{2}", schm, host, path);
|
var url = String.Format ("{0}://{1}{2}", schm, host, path);
|
||||||
|
|
||||||
Uri res;
|
Uri ret;
|
||||||
if (!Uri.TryCreate (url, UriKind.Absolute, out res))
|
if (!Uri.TryCreate (url, UriKind.Absolute, out ret))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return res;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static IPrincipal CreateUser (
|
internal static IPrincipal CreateUser (
|
||||||
|
Loading…
Reference in New Issue
Block a user