@@ -19,6 +19,7 @@ RUN dotnet publish src/Servers/EffinitiveServer/EffinitiveServer.csproj -c Relea
1919FROM mcr.microsoft.com/dotnet/runtime:10.0
2020WORKDIR /app
2121COPY --from=build /app .
22+ USER $APP_UID
2223ENTRYPOINT ["dotnet" , "EffinitiveServer.dll" , "8080" ]
2324```
2425
@@ -40,97 +41,102 @@ var app = EffinitiveApp
4041Console .WriteLine ($" Effinitive listening on http://localhost:{port }" );
4142await app .RunAsync ();
4243
43- // ── GET / ──────────────────────────────────────────────────────
44-
45- sealed class GetRoot : NoRequestEndpointBase <string >
44+ namespace EffinitiveServer .Endpoints
4645{
47- protected override string Method => " GET" ;
48- protected override string Route => " /" ;
49- protected override string ContentType => " text/plain" ;
46+ // ── GET / ──────────────────────────────────────────────────────
5047
51- public override ValueTask <string > HandleAsync (CancellationToken ct = default )
52- => ValueTask .FromResult (" OK" );
53- }
48+ sealed class GetRoot : NoRequestEndpointBase <string >
49+ {
50+ protected override string Method => " GET" ;
51+ protected override string Route => " /" ;
52+ protected override string ContentType => Helpers .TextPlain ;
5453
55- // ── POST / ─────────────────────────────────────────────────────
54+ public override ValueTask <string > HandleAsync (CancellationToken ct = default )
55+ => ValueTask .FromResult (" OK" );
56+ }
5657
57- sealed class PostRoot : NoRequestEndpointBase <string >
58- {
59- protected override string Method => " POST" ;
60- protected override string Route => " /" ;
61- protected override string ContentType => " text/plain" ;
58+ // ── POST / ─────────────────────────────────────────────────────
6259
63- public override ValueTask <string > HandleAsync ( CancellationToken ct = default )
60+ sealed class PostRoot : NoRequestEndpointBase <string >
6461 {
65- var body = HttpContext ? .Body ;
66- return ValueTask .FromResult (body is { Length : > 0 } ? Encoding .UTF8 .GetString (body ) : " " );
62+ protected override string Method => " POST" ;
63+ protected override string Route => " /" ;
64+ protected override string ContentType => Helpers .TextPlain ;
65+
66+ public override ValueTask <string > HandleAsync (CancellationToken ct = default )
67+ {
68+ var body = HttpContext ? .Body ;
69+ return ValueTask .FromResult (body is { Length : > 0 } ? Encoding .UTF8 .GetString (body ) : " " );
70+ }
6771 }
68- }
6972
70- // ── GET/POST /echo ────────────────────────────────────────────
73+ // ── GET/POST /echo ────────────────────────────────────────────
7174
72- sealed class EchoGet : NoRequestEndpointBase <string >
73- {
74- protected override string Method => " GET" ;
75- protected override string Route => " /echo" ;
76- protected override string ContentType => " text/plain" ;
77-
78- public override ValueTask <string > HandleAsync (CancellationToken ct = default )
79- => ValueTask .FromResult (Helpers .EchoHeaders (HttpContext ));
80- }
81-
82- sealed class EchoPost : NoRequestEndpointBase <string >
83- {
84- protected override string Method => " POST" ;
85- protected override string Route => " /echo" ;
86- protected override string ContentType => " text/plain" ;
87-
88- public override ValueTask <string > HandleAsync (CancellationToken ct = default )
89- => ValueTask .FromResult (Helpers .EchoHeaders (HttpContext ));
90- }
75+ sealed class EchoGet : NoRequestEndpointBase <string >
76+ {
77+ protected override string Method => " GET" ;
78+ protected override string Route => " /echo" ;
79+ protected override string ContentType => Helpers .TextPlain ;
9180
92- // ── GET/POST /cookie ──────────────────────────────────────────
81+ public override ValueTask <string > HandleAsync (CancellationToken ct = default )
82+ => ValueTask .FromResult (Helpers .EchoHeaders (HttpContext ));
83+ }
9384
94- sealed class CookieGet : NoRequestEndpointBase <string >
95- {
96- protected override string Method => " GET " ;
97- protected override string Route => " /cookie " ;
98- protected override string ContentType => " text/plain " ;
85+ sealed class EchoPost : NoRequestEndpointBase <string >
86+ {
87+ protected override string Method => " POST " ;
88+ protected override string Route => " /echo " ;
89+ protected override string ContentType => Helpers . TextPlain ;
9990
100- public override ValueTask <string > HandleAsync (CancellationToken ct = default )
101- => ValueTask .FromResult (Helpers .ParseCookies (HttpContext ));
102- }
91+ public override ValueTask <string > HandleAsync (CancellationToken ct = default )
92+ => ValueTask .FromResult (Helpers .EchoHeaders (HttpContext ));
93+ }
10394
104- sealed class CookiePost : NoRequestEndpointBase <string >
105- {
106- protected override string Method => " POST" ;
107- protected override string Route => " /cookie" ;
108- protected override string ContentType => " text/plain" ;
95+ // ── GET/POST /cookie ──────────────────────────────────────────
10996
110- public override ValueTask <string > HandleAsync (CancellationToken ct = default )
111- => ValueTask .FromResult (Helpers .ParseCookies (HttpContext ));
112- }
97+ sealed class CookieGet : NoRequestEndpointBase <string >
98+ {
99+ protected override string Method => " GET" ;
100+ protected override string Route => " /cookie" ;
101+ protected override string ContentType => Helpers .TextPlain ;
113102
114- // ── Shared helpers ────────────────────────────────────────────
103+ public override ValueTask <string > HandleAsync (CancellationToken ct = default )
104+ => ValueTask .FromResult (Helpers .ParseCookies (HttpContext ));
105+ }
115106
116- static class Helpers
117- {
118- public static string EchoHeaders (HttpRequest ? ctx )
107+ sealed class CookiePost : NoRequestEndpointBase <string >
119108 {
120- if (ctx ? .Headers is null ) return " " ;
121- var sb = new StringBuilder ();
122- foreach (var h in ctx .Headers )
123- sb .Append (h .Key ).Append (" : " ).Append (h .Value ).Append (" \r\n " );
124- return sb .ToString ();
109+ protected override string Method => " POST" ;
110+ protected override string Route => " /cookie" ;
111+ protected override string ContentType => Helpers .TextPlain ;
112+
113+ public override ValueTask <string > HandleAsync (CancellationToken ct = default )
114+ => ValueTask .FromResult (Helpers .ParseCookies (HttpContext ));
125115 }
126116
127- public static string ParseCookies (HttpRequest ? ctx )
117+ // ── Shared helpers ────────────────────────────────────────────
118+
119+ static class Helpers
128120 {
129- if (ctx is null ) return " " ;
130- var sb = new StringBuilder ();
131- foreach (var c in ctx .Cookies )
132- sb .Append (c .Key ).Append ('=' ).Append (c .Value ).Append (" \r\n " );
133- return sb .ToString ();
121+ public const string TextPlain = " text/plain" ;
122+
123+ public static string EchoHeaders (HttpRequest ? ctx )
124+ {
125+ if (ctx ? .Headers is null ) return " " ;
126+ var sb = new StringBuilder ();
127+ foreach (var h in ctx .Headers )
128+ sb .Append (h .Key ).Append (" : " ).Append (h .Value ).Append (" \r\n " );
129+ return sb .ToString ();
130+ }
131+
132+ public static string ParseCookies (HttpRequest ? ctx )
133+ {
134+ if (ctx is null ) return " " ;
135+ var sb = new StringBuilder ();
136+ foreach (var c in ctx .Cookies )
137+ sb .Append (c .Key ).Append ('=' ).Append (c .Value ).Append (" \r\n " );
138+ return sb .ToString ();
139+ }
134140 }
135141}
136142```
0 commit comments