Skip to content

Commit fa6c6a8

Browse files
committed
Update Effinitive server documentation and refactor endpoint classes
1 parent baeef4f commit fa6c6a8

2 files changed

Lines changed: 78 additions & 72 deletions

File tree

docs/content/servers/effinitive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ static class Helpers
167167
document.getElementById('server-summary').innerHTML = '<p><em>No probe data available yet. Run the Probe workflow on <code>main</code> to generate results.</em></p>';
168168
return;
169169
}
170-
ProbeRender.renderServerPage('Nginx');
170+
ProbeRender.renderServerPage('Effinitive');
171171
})();
172172
</script>
Lines changed: 77 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text;
22
using EffinitiveFramework.Core;
33
using EffinitiveFramework.Core.Http;
4+
using EffinitiveServer.Endpoints;
45

56
var port = args.Length > 0 && int.TryParse(args[0], out var p) ? p : 8080;
67

@@ -13,96 +14,101 @@
1314
Console.WriteLine($"Effinitive listening on http://localhost:{port}");
1415
await app.RunAsync();
1516

16-
// ── GET / ──────────────────────────────────────────────────────
17-
18-
sealed class GetRoot : NoRequestEndpointBase<string>
17+
namespace EffinitiveServer.Endpoints
1918
{
20-
protected override string Method => "GET";
21-
protected override string Route => "/";
22-
protected override string ContentType => "text/plain";
19+
// ── GET / ──────────────────────────────────────────────────────
2320

24-
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
25-
=> ValueTask.FromResult("OK");
26-
}
21+
sealed class GetRoot : NoRequestEndpointBase<string>
22+
{
23+
protected override string Method => "GET";
24+
protected override string Route => "/";
25+
protected override string ContentType => Helpers.TextPlain;
2726

28-
// ── POST / ─────────────────────────────────────────────────────
27+
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
28+
=> ValueTask.FromResult("OK");
29+
}
2930

30-
sealed class PostRoot : NoRequestEndpointBase<string>
31-
{
32-
protected override string Method => "POST";
33-
protected override string Route => "/";
34-
protected override string ContentType => "text/plain";
31+
// ── POST / ─────────────────────────────────────────────────────
3532

36-
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
33+
sealed class PostRoot : NoRequestEndpointBase<string>
3734
{
38-
var body = HttpContext?.Body;
39-
return ValueTask.FromResult(body is { Length: > 0 } ? Encoding.UTF8.GetString(body) : "");
35+
protected override string Method => "POST";
36+
protected override string Route => "/";
37+
protected override string ContentType => Helpers.TextPlain;
38+
39+
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
40+
{
41+
var body = HttpContext?.Body;
42+
return ValueTask.FromResult(body is { Length: > 0 } ? Encoding.UTF8.GetString(body) : "");
43+
}
4044
}
41-
}
4245

43-
// ── GET/POST /echo ────────────────────────────────────────────
46+
// ── GET/POST /echo ────────────────────────────────────────────
4447

45-
sealed class EchoGet : NoRequestEndpointBase<string>
46-
{
47-
protected override string Method => "GET";
48-
protected override string Route => "/echo";
49-
protected override string ContentType => "text/plain";
50-
51-
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
52-
=> ValueTask.FromResult(Helpers.EchoHeaders(HttpContext));
53-
}
54-
55-
sealed class EchoPost : NoRequestEndpointBase<string>
56-
{
57-
protected override string Method => "POST";
58-
protected override string Route => "/echo";
59-
protected override string ContentType => "text/plain";
60-
61-
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
62-
=> ValueTask.FromResult(Helpers.EchoHeaders(HttpContext));
63-
}
48+
sealed class EchoGet : NoRequestEndpointBase<string>
49+
{
50+
protected override string Method => "GET";
51+
protected override string Route => "/echo";
52+
protected override string ContentType => Helpers.TextPlain;
6453

65-
// ── GET/POST /cookie ──────────────────────────────────────────
54+
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
55+
=> ValueTask.FromResult(Helpers.EchoHeaders(HttpContext));
56+
}
6657

67-
sealed class CookieGet : NoRequestEndpointBase<string>
68-
{
69-
protected override string Method => "GET";
70-
protected override string Route => "/cookie";
71-
protected override string ContentType => "text/plain";
58+
sealed class EchoPost : NoRequestEndpointBase<string>
59+
{
60+
protected override string Method => "POST";
61+
protected override string Route => "/echo";
62+
protected override string ContentType => Helpers.TextPlain;
7263

73-
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
74-
=> ValueTask.FromResult(Helpers.ParseCookies(HttpContext));
75-
}
64+
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
65+
=> ValueTask.FromResult(Helpers.EchoHeaders(HttpContext));
66+
}
7667

77-
sealed class CookiePost : NoRequestEndpointBase<string>
78-
{
79-
protected override string Method => "POST";
80-
protected override string Route => "/cookie";
81-
protected override string ContentType => "text/plain";
68+
// ── GET/POST /cookie ──────────────────────────────────────────
8269

83-
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
84-
=> ValueTask.FromResult(Helpers.ParseCookies(HttpContext));
85-
}
70+
sealed class CookieGet : NoRequestEndpointBase<string>
71+
{
72+
protected override string Method => "GET";
73+
protected override string Route => "/cookie";
74+
protected override string ContentType => Helpers.TextPlain;
8675

87-
// ── Shared helpers ────────────────────────────────────────────
76+
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
77+
=> ValueTask.FromResult(Helpers.ParseCookies(HttpContext));
78+
}
8879

89-
static class Helpers
90-
{
91-
public static string EchoHeaders(HttpRequest? ctx)
80+
sealed class CookiePost : NoRequestEndpointBase<string>
9281
{
93-
if (ctx?.Headers is null) return "";
94-
var sb = new StringBuilder();
95-
foreach (var h in ctx.Headers)
96-
sb.Append(h.Key).Append(": ").Append(h.Value).Append("\r\n");
97-
return sb.ToString();
82+
protected override string Method => "POST";
83+
protected override string Route => "/cookie";
84+
protected override string ContentType => Helpers.TextPlain;
85+
86+
public override ValueTask<string> HandleAsync(CancellationToken ct = default)
87+
=> ValueTask.FromResult(Helpers.ParseCookies(HttpContext));
9888
}
9989

100-
public static string ParseCookies(HttpRequest? ctx)
90+
// ── Shared helpers ────────────────────────────────────────────
91+
92+
static class Helpers
10193
{
102-
if (ctx is null) return "";
103-
var sb = new StringBuilder();
104-
foreach (var c in ctx.Cookies)
105-
sb.Append(c.Key).Append('=').Append(c.Value).Append("\r\n");
106-
return sb.ToString();
94+
public const string TextPlain = "text/plain";
95+
96+
public static string EchoHeaders(HttpRequest? ctx)
97+
{
98+
if (ctx?.Headers is null) return "";
99+
var sb = new StringBuilder();
100+
foreach (var h in ctx.Headers)
101+
sb.Append(h.Key).Append(": ").Append(h.Value).Append("\r\n");
102+
return sb.ToString();
103+
}
104+
105+
public static string ParseCookies(HttpRequest? ctx)
106+
{
107+
if (ctx is null) return "";
108+
var sb = new StringBuilder();
109+
foreach (var c in ctx.Cookies)
110+
sb.Append(c.Key).Append('=').Append(c.Value).Append("\r\n");
111+
return sb.ToString();
112+
}
107113
}
108114
}

0 commit comments

Comments
 (0)