This commit is contained in:
uwaa 2024-11-15 15:17:21 +00:00
parent ed55f618aa
commit a41c46175b
2 changed files with 9 additions and 10 deletions

2
HTTP

@ -1 +1 @@
Subproject commit 17816628e836571660906dd7c7c9c9aabd9abfe1
Subproject commit 553f96351678f9edb1c82a8d7540df3345013ad6

View file

@ -87,7 +87,7 @@ static class Program
static async Task<HttpResponse?> Root(HttpRequest req)
{
if (req.IsWebsocket)
return await Websocket(req);
return Websocket(req);
byte[] indexFile = await File.ReadAllBytesAsync("www-static/index.htm");
HttpContent html = new HttpContent(new MIMEType("text", "html"), indexFile);
@ -97,23 +97,22 @@ static class Program
/// <summary>
/// Websocket endpoint
/// </summary>
static async Task<Empty> Websocket(HttpRequest client)
static HttpResponse? Websocket(HttpRequest client)
{
Websocket? ws = await client.UpgradeToWebsocket("test");
if (ws == null)
return new Empty();
return client.UpgradeToWebsocket(HandleWebsocket, "test");
}
static async Task<CloseStatus> HandleWebsocket(Websocket ws)
{
DataFrame payload = await ws.Read();
if (payload.Opcode != WSOpcode.Close)
{
string result = payload.AsString();
await ws.Write(true, $"Echoing message: \"{result}\"");
await ws.Write($"Echoing message: \"{result}\"");
}
ws.Close(CloseStatus.NormalClosure);
return new Empty();
return CloseStatus.NormalClosure;
}
/// <summary>