Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions websocket-sharp/Server/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private string checkIfCertificateExists ()
return !(usr || port) ? "The secure connection requires a server certificate." : null;
}

private void init (string hostname, System.Net.IPAddress address, int port, bool secure)
private void init (string hostname, System.Net.IPAddress address, int port, bool secure, bool wildcardServicesPath = false)
{
_hostname = hostname ?? address.ToString ();
_address = address;
Expand All @@ -638,7 +638,7 @@ private void init (string hostname, System.Net.IPAddress address, int port, bool
String.Format ("http{0}://{1}:{2}/", secure ? "s" : "", _hostname, port));

_logger = _listener.Log;
_services = new WebSocketServiceManager (_logger);
_services = new WebSocketServiceManager (_logger, wildcardServicesPath);
_sync = new object ();

var os = Environment.OSVersion;
Expand Down
20 changes: 10 additions & 10 deletions websocket-sharp/Server/WebSocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public class WebSocketServer
/// An instance initialized by this constructor listens for the incoming connection requests on
/// port 80.
/// </remarks>
public WebSocketServer ()
public WebSocketServer (bool wildcardServicesPath = false)
{
init (null, System.Net.IPAddress.Any, 80, false);
init (null, System.Net.IPAddress.Any, 80, false, wildcardServicesPath);
}

/// <summary>
Expand Down Expand Up @@ -149,7 +149,7 @@ public WebSocketServer (int port)
/// <paramref name="url"/> is invalid.
/// </para>
/// </exception>
public WebSocketServer (string url)
public WebSocketServer (string url, bool wildcardServicesPath = false)
{
if (url == null)
throw new ArgumentNullException ("url");
Expand All @@ -167,7 +167,7 @@ public WebSocketServer (string url)
if (!addr.IsLocal ())
throw new ArgumentException ("The host part isn't a local host name: " + url, "url");

init (host, addr, uri.Port, uri.Scheme == "wss");
init (host, addr, uri.Port, uri.Scheme == "wss", wildcardServicesPath);
}

/// <summary>
Expand All @@ -188,13 +188,13 @@ public WebSocketServer (string url)
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="port"/> isn't between 1 and 65535 inclusive.
/// </exception>
public WebSocketServer (int port, bool secure)
public WebSocketServer (int port, bool secure, bool wildcardServicesPath = false)
{
if (!port.IsPortNumber ())
throw new ArgumentOutOfRangeException (
"port", "Not between 1 and 65535 inclusive: " + port);

init (null, System.Net.IPAddress.Any, port, secure);
init (null, System.Net.IPAddress.Any, port, secure, wildcardServicesPath);
}

/// <summary>
Expand Down Expand Up @@ -258,7 +258,7 @@ public WebSocketServer (System.Net.IPAddress address, int port)
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="port"/> isn't between 1 and 65535 inclusive.
/// </exception>
public WebSocketServer (System.Net.IPAddress address, int port, bool secure)
public WebSocketServer (System.Net.IPAddress address, int port, bool secure, bool wildcardServicesPath = false)
{
if (address == null)
throw new ArgumentNullException ("address");
Expand All @@ -270,7 +270,7 @@ public WebSocketServer (System.Net.IPAddress address, int port, bool secure)
throw new ArgumentOutOfRangeException (
"port", "Not between 1 and 65535 inclusive: " + port);

init (null, address, port, secure);
init (null, address, port, secure, wildcardServicesPath);
}

#endregion
Expand Down Expand Up @@ -592,7 +592,7 @@ private string checkIfCertificateExists ()
: null;
}

private void init (string hostname, System.Net.IPAddress address, int port, bool secure)
private void init (string hostname, System.Net.IPAddress address, int port, bool secure, bool wildcardServicesPath)
{
_hostname = hostname ?? address.ToString ();
_address = address;
Expand All @@ -603,7 +603,7 @@ private void init (string hostname, System.Net.IPAddress address, int port, bool
_dnsStyle = Uri.CheckHostName (hostname) == UriHostNameType.Dns;
_listener = new TcpListener (address, port);
_logger = new Logger ();
_services = new WebSocketServiceManager (_logger);
_services = new WebSocketServiceManager (_logger, wildcardServicesPath);
_sync = new object ();
}

Expand Down
23 changes: 18 additions & 5 deletions websocket-sharp/Server/WebSocketServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ public class WebSocketServiceManager
private volatile ServerState _state;
private object _sync;
private TimeSpan _waitTime;
private bool _wildcardServices;

#endregion

#region Internal Constructors

internal WebSocketServiceManager ()
: this (new Logger ())
internal WebSocketServiceManager (bool wildcardServices = false)
: this (new Logger (), wildcardServices)
{
}

internal WebSocketServiceManager (Logger logger)
internal WebSocketServiceManager (Logger logger, bool wildcardServices)
{
_logger = logger;

Expand All @@ -69,6 +70,7 @@ internal WebSocketServiceManager (Logger logger)
_state = ServerState.Ready;
_sync = ((ICollection) _hosts).SyncRoot;
_waitTime = TimeSpan.FromSeconds (1);
_wildcardServices = wildcardServices;
}

#endregion
Expand Down Expand Up @@ -314,8 +316,19 @@ internal bool InternalTryGetServiceHost (string path, out WebSocketServiceHost h
{
bool ret;
lock (_sync) {
path = HttpUtility.UrlDecode (path).TrimEndSlash ();
ret = _hosts.TryGetValue (path, out host);
if (!_wildcardServices) {
path = HttpUtility.UrlDecode (path).TrimEndSlash ();
}
else {
foreach (var key in _hosts.Keys) {
if (new System.Text.RegularExpressions.Regex(key).IsMatch(path)) {
path = key;
break;
}
}
}

ret = _hosts.TryGetValue(path, out host);
}

if (!ret)
Expand Down