Fix connecting to web sockets with regex urls

This commit is contained in:
Frank A. Krueger 2020-03-08 18:45:21 -07:00
parent fe690fd13c
commit 04211c0f67
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
2 changed files with 21 additions and 3 deletions

View File

@ -221,6 +221,13 @@ namespace Ooui
return url; return url;
} }
public static string GetWebSocketUrl (string path)
{
var localhost = host == "*" ? "localhost" : host;
var url = $"ws://{localhost}:{port}{path}";
return url;
}
public static void WaitUntilStarted () => started.WaitOne (); public static void WaitUntilStarted () => started.WaitOne ();
static void Start () static void Start ()
@ -561,6 +568,9 @@ namespace Ooui
if (m.Success) { if (m.Success) {
pp = p; pp = p;
found = true; found = true;
for (var ig = 1; ig < m.Groups.Count; ig++) {
variables[p.RegexPath.GroupNameFromNumber (ig)] = m.Groups[ig].Value;
}
break; break;
} }
} }

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#if NUNIT #if NUNIT
@ -83,14 +85,20 @@ namespace Tests
} }
[TestMethod] [TestMethod]
public void PublishElementPatternUrl () public async Task PublishElementPatternUrl ()
{ {
bool gotRequest = false;
UI.Publish ("/pattern/(?<id>[a-z0-9]+)", x => { UI.Publish ("/pattern/(?<id>[a-z0-9]+)", x => {
gotRequest = true;
Assert.AreEqual ("fhe48yf", x["id"]); Assert.AreEqual ("fhe48yf", x["id"]);
return new Paragraph (x["id"]); return new Paragraph (x["id"]);
}); });
var r = DownloadUI ("/pattern/fhe48yf"); UI.WaitUntilStarted ();
Assert.IsTrue (r.Length > 200); var ws = new ClientWebSocket ();
ws.Options.AddSubProtocol ("ooui");
var url = new Uri (UI.GetWebSocketUrl ("/pattern/fhe48yf"));
await ws.ConnectAsync (url, CancellationToken.None);
Assert.IsTrue (gotRequest);
} }
[TestMethod] [TestMethod]