[Modify] Replace it
This commit is contained in:
parent
400ba6ecd9
commit
a007be11ad
@ -280,66 +280,6 @@ namespace WebSocketSharp.Net
|
||||
return false;
|
||||
}
|
||||
|
||||
private HttpListener searchHttpListener (Uri uri, out HttpListenerPrefix prefix)
|
||||
{
|
||||
prefix = null;
|
||||
|
||||
if (uri == null)
|
||||
return null;
|
||||
|
||||
var host = uri.Host;
|
||||
var dns = Uri.CheckHostName (host) == UriHostNameType.Dns;
|
||||
var port = uri.Port.ToString ();
|
||||
var path = HttpUtility.UrlDecode (uri.AbsolutePath);
|
||||
var pathSlash = path[path.Length - 1] != '/' ? path + "/" : path;
|
||||
|
||||
HttpListener bestMatch = null;
|
||||
|
||||
if (host != null && host.Length > 0) {
|
||||
var bestLen = -1;
|
||||
foreach (var pref in _prefixes.Keys) {
|
||||
if (dns) {
|
||||
var prefHost = pref.Host;
|
||||
if (Uri.CheckHostName (prefHost) == UriHostNameType.Dns && prefHost != host)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pref.Port != port)
|
||||
continue;
|
||||
|
||||
var prefPath = pref.Path;
|
||||
|
||||
var len = prefPath.Length;
|
||||
if (len < bestLen)
|
||||
continue;
|
||||
|
||||
if (path.StartsWith (prefPath) || pathSlash.StartsWith (prefPath)) {
|
||||
bestLen = len;
|
||||
bestMatch = _prefixes[pref];
|
||||
prefix = pref;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestLen != -1)
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
var prefs = _unhandled;
|
||||
bestMatch = searchHttpListenerFromSpecial (path, prefs, out prefix);
|
||||
if (bestMatch == null && pathSlash != path)
|
||||
bestMatch = searchHttpListenerFromSpecial (pathSlash, prefs, out prefix);
|
||||
|
||||
if (bestMatch != null)
|
||||
return bestMatch;
|
||||
|
||||
prefs = _all;
|
||||
bestMatch = searchHttpListenerFromSpecial (path, prefs, out prefix);
|
||||
if (bestMatch == null && pathSlash != path)
|
||||
bestMatch = searchHttpListenerFromSpecial (pathSlash, prefs, out prefix);
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
private static HttpListener searchHttpListenerFromSpecial (
|
||||
string path, List<HttpListenerPrefix> prefixes
|
||||
)
|
||||
@ -366,51 +306,10 @@ namespace WebSocketSharp.Net
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
private static HttpListener searchHttpListenerFromSpecial (
|
||||
string path, List<HttpListenerPrefix> prefixes, out HttpListenerPrefix prefix
|
||||
)
|
||||
{
|
||||
prefix = null;
|
||||
|
||||
if (prefixes == null)
|
||||
return null;
|
||||
|
||||
HttpListener bestMatch = null;
|
||||
|
||||
var bestLen = -1;
|
||||
foreach (var pref in prefixes) {
|
||||
var prefPath = pref.Path;
|
||||
|
||||
var len = prefPath.Length;
|
||||
if (len < bestLen)
|
||||
continue;
|
||||
|
||||
if (path.StartsWith (prefPath)) {
|
||||
bestLen = len;
|
||||
bestMatch = pref.Listener;
|
||||
prefix = pref;
|
||||
}
|
||||
}
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal bool BindHttpListenerTo (HttpListenerContext context)
|
||||
{
|
||||
HttpListenerPrefix pref;
|
||||
var lsnr = searchHttpListener (context.Request.Url, out pref);
|
||||
if (lsnr == null)
|
||||
return false;
|
||||
|
||||
context.Listener = lsnr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool CertificateExists (int port, string folderPath)
|
||||
{
|
||||
if (folderPath == null || folderPath.Length == 0)
|
||||
|
@ -275,12 +275,12 @@ namespace WebSocketSharp.Net
|
||||
return;
|
||||
}
|
||||
|
||||
if (!conn._listener.BindHttpListenerTo (conn._context)) {
|
||||
HttpListener lsnr;
|
||||
if (!conn._listener.TrySearchHttpListener (conn._context.Request.Url, out lsnr)) {
|
||||
conn.SendError (null, 404);
|
||||
return;
|
||||
}
|
||||
|
||||
var lsnr = conn._context.Listener;
|
||||
if (conn._lastListener != lsnr) {
|
||||
conn.removeConnection ();
|
||||
if (!lsnr.AddConnection (conn)) {
|
||||
@ -291,6 +291,7 @@ namespace WebSocketSharp.Net
|
||||
conn._lastListener = lsnr;
|
||||
}
|
||||
|
||||
conn._context.Listener = lsnr;
|
||||
if (!conn._context.Authenticate ())
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user