Fix connecting to web sockets with regex urls
This commit is contained in:
parent
fe690fd13c
commit
04211c0f67
10
Ooui/UI.cs
10
Ooui/UI.cs
|
@ -221,6 +221,13 @@ namespace Ooui
|
|||
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 ();
|
||||
|
||||
static void Start ()
|
||||
|
@ -561,6 +568,9 @@ namespace Ooui
|
|||
if (m.Success) {
|
||||
pp = p;
|
||||
found = true;
|
||||
for (var ig = 1; ig < m.Groups.Count; ig++) {
|
||||
variables[p.RegexPath.GroupNameFromNumber (ig)] = m.Groups[ig].Value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if NUNIT
|
||||
|
@ -83,14 +85,20 @@ namespace Tests
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PublishElementPatternUrl ()
|
||||
public async Task PublishElementPatternUrl ()
|
||||
{
|
||||
bool gotRequest = false;
|
||||
UI.Publish ("/pattern/(?<id>[a-z0-9]+)", x => {
|
||||
gotRequest = true;
|
||||
Assert.AreEqual ("fhe48yf", x["id"]);
|
||||
return new Paragraph (x["id"]);
|
||||
});
|
||||
var r = DownloadUI ("/pattern/fhe48yf");
|
||||
Assert.IsTrue (r.Length > 200);
|
||||
UI.WaitUntilStarted ();
|
||||
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]
|
||||
|
|
Loading…
Reference in New Issue