From 05916b9e1ed73b51556223f00064e495cbf162e3 Mon Sep 17 00:00:00 2001 From: uwaa Date: Sun, 27 Oct 2024 23:51:38 +0000 Subject: [PATCH] update example --- Example/Program.cs | 39 +++++++++++++++++++++++++++------------ MiniHTTP | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Example/Program.cs b/Example/Program.cs index fa41e44..660e669 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -34,35 +34,40 @@ static class Program static Router CreateRouter() { - Router router = new Router(NotFound); - router.Use("*", new CORS()); - router.Add(HttpMethod.GET, "test", Test); - router.Static("www-static"); - router.Static("www-dynamic"); - router.Add(HttpMethod.GET, "", Root); + Router root = new Router(NotFound); + root.Use("*", new CORS()); + root.Add(HttpMethod.GET, "redirect", Redirect); + root.Static("www-static"); + root.Static("www-dynamic"); + root.Add(HttpMethod.GET, "", Root); - return router; + Router nested = new Router(NotFound); + nested.Add(HttpMethod.GET, "example1", Nested1); + nested.Add(HttpMethod.GET, "example2", Nested2); + root.Use("nested", nested); + + return root; } - static async Task Root(HttpRequest client, ParameterCollection parameters) + static async Task Root(HttpRequest client, VariableCollection parameters) { if (client.Headers.TryGetValue("Upgrade", out string? connection) && connection.Equals("websocket", StringComparison.OrdinalIgnoreCase)) return await Websocket(client); else - return new HttpContent("text/html", await File.ReadAllBytesAsync("www-static/index.htm")); + return new OK(new HttpContent("text/html", await File.ReadAllBytesAsync("www-static/index.htm"))); } - static HttpResponse Test(HttpRequest client, ParameterCollection parameters) + static Redirect Redirect(HttpRequest client, VariableCollection parameters) { return new Redirect("/"); } - static HttpResponse NotFound(HttpRequest client, ParameterCollection parameters) + static NotFound NotFound(HttpRequest client, VariableCollection parameters) { return new NotFound("File not found"); } - static async Task Websocket(HttpRequest client) + static async Task Websocket(HttpRequest client) { Websocket? ws = await client.UpgradeToWebsocket("test"); if (ws == null) @@ -81,4 +86,14 @@ static class Program return new Empty(); } + + static OK Nested1(HttpRequest client, VariableCollection parameters) + { + return new OK("Foo"); + } + + static OK Nested2(HttpRequest client, VariableCollection parameters) + { + return new OK("Bar"); + } } diff --git a/MiniHTTP b/MiniHTTP index c302da3..bc8ce1a 160000 --- a/MiniHTTP +++ b/MiniHTTP @@ -1 +1 @@ -Subproject commit c302da3713a77336b724df395c2cd33e7f650c4a +Subproject commit bc8ce1a19af6f398fcb05d597f356adf3e3f2e00