-
Notifications
You must be signed in to change notification settings - Fork 7
Add Effinitive server implementation #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
baeef4f
Add Effinitive server implementation with Docker support
HenryBartosch fa6c6a8
Update Effinitive server documentation and refactor endpoint classes
HenryBartosch a7397b8
Refactor Dockerfile and update EffinitiveFramework.Core version in pr…
HenryBartosch 18b924e
Updated md document
HenryBartosch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| --- | ||
| title: "Effinitive" | ||
| toc: false | ||
| breadcrumbs: false | ||
| --- | ||
|
|
||
| **Language:** C# · [View source on GitHub](https://github.com/MDA2AV/Http11Probe/tree/main/src/Servers/EffinitiveServer) | ||
|
|
||
| ## Dockerfile | ||
|
|
||
| ```dockerfile | ||
| FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build | ||
| WORKDIR /src | ||
| COPY Directory.Build.props . | ||
| COPY src/Servers/EffinitiveServer/ src/Servers/EffinitiveServer/ | ||
| RUN dotnet restore src/Servers/EffinitiveServer/EffinitiveServer.csproj | ||
| RUN dotnet publish src/Servers/EffinitiveServer/EffinitiveServer.csproj -c Release -o /app --no-restore | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/runtime:10.0 | ||
| WORKDIR /app | ||
| COPY --from=build /app . | ||
| ENTRYPOINT ["dotnet", "EffinitiveServer.dll", "8080"] | ||
| ``` | ||
|
|
||
| ## Source — `Program.cs` | ||
|
|
||
| ```csharp | ||
| using System.Text; | ||
| using EffinitiveFramework.Core; | ||
| using EffinitiveFramework.Core.Http; | ||
|
|
||
| var port = args.Length > 0 && int.TryParse(args[0], out var p) ? p : 8080; | ||
|
|
||
| var app = EffinitiveApp | ||
| .Create() | ||
| .UsePort(port) | ||
| .MapEndpoints() | ||
| .Build(); | ||
|
|
||
| Console.WriteLine($"Effinitive listening on http://localhost:{port}"); | ||
| await app.RunAsync(); | ||
|
|
||
| // ── GET / ────────────────────────────────────────────────────── | ||
|
|
||
| sealed class GetRoot : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "GET"; | ||
| protected override string Route => "/"; | ||
| protected override string ContentType => "text/plain"; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult("OK"); | ||
| } | ||
|
|
||
| // ── POST / ───────────────────────────────────────────────────── | ||
|
|
||
| sealed class PostRoot : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "POST"; | ||
| protected override string Route => "/"; | ||
| protected override string ContentType => "text/plain"; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| { | ||
| var body = HttpContext?.Body; | ||
| return ValueTask.FromResult(body is { Length: > 0 } ? Encoding.UTF8.GetString(body) : ""); | ||
| } | ||
| } | ||
|
|
||
| // ── GET/POST /echo ──────────────────────────────────────────── | ||
|
|
||
| sealed class EchoGet : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "GET"; | ||
| protected override string Route => "/echo"; | ||
| protected override string ContentType => "text/plain"; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.EchoHeaders(HttpContext)); | ||
| } | ||
|
|
||
| sealed class EchoPost : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "POST"; | ||
| protected override string Route => "/echo"; | ||
| protected override string ContentType => "text/plain"; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.EchoHeaders(HttpContext)); | ||
| } | ||
|
|
||
| // ── GET/POST /cookie ────────────────────────────────────────── | ||
|
|
||
| sealed class CookieGet : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "GET"; | ||
| protected override string Route => "/cookie"; | ||
| protected override string ContentType => "text/plain"; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.ParseCookies(HttpContext)); | ||
| } | ||
|
|
||
| sealed class CookiePost : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "POST"; | ||
| protected override string Route => "/cookie"; | ||
| protected override string ContentType => "text/plain"; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.ParseCookies(HttpContext)); | ||
| } | ||
|
|
||
| // ── Shared helpers ──────────────────────────────────────────── | ||
|
|
||
| static class Helpers | ||
| { | ||
| public static string EchoHeaders(HttpRequest? ctx) | ||
| { | ||
| if (ctx?.Headers is null) return ""; | ||
| var sb = new StringBuilder(); | ||
| foreach (var h in ctx.Headers) | ||
| sb.Append(h.Key).Append(": ").Append(h.Value).Append("\r\n"); | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| public static string ParseCookies(HttpRequest? ctx) | ||
| { | ||
| if (ctx is null) return ""; | ||
| var sb = new StringBuilder(); | ||
| foreach (var c in ctx.Cookies) | ||
| sb.Append(c.Key).Append('=').Append(c.Value).Append("\r\n"); | ||
| return sb.ToString(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Test Results | ||
|
|
||
| <div id="server-summary"><p><em>Loading results...</em></p></div> | ||
|
|
||
| ### Compliance | ||
|
|
||
| <div id="results-compliance"></div> | ||
|
|
||
| ### Smuggling | ||
|
|
||
| <div id="results-smuggling"></div> | ||
|
|
||
| ### Malformed Input | ||
|
|
||
| <div id="results-malformedinput"></div> | ||
|
|
||
| ### Caching | ||
|
|
||
| <div id="results-capabilities"></div> | ||
|
|
||
| ### Cookies | ||
|
|
||
| <div id="results-cookies"></div> | ||
|
|
||
| <script src="/probe/data.js"></script> | ||
| <script src="/probe/render.js"></script> | ||
| <script> | ||
| (function() { | ||
| if (!window.PROBE_DATA) { | ||
| 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>'; | ||
| return; | ||
| } | ||
| ProbeRender.renderServerPage('Effinitive'); | ||
| })(); | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build | ||
| WORKDIR /src | ||
| COPY Directory.Build.props . | ||
| COPY src/Servers/EffinitiveServer/ src/Servers/EffinitiveServer/ | ||
| RUN dotnet restore src/Servers/EffinitiveServer/EffinitiveServer.csproj | ||
| RUN dotnet publish src/Servers/EffinitiveServer/EffinitiveServer.csproj -c Release -o /app --no-restore | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/runtime:10.0 | ||
| WORKDIR /app | ||
| COPY --from=build /app . | ||
| ENTRYPOINT ["dotnet", "EffinitiveServer.dll", "8080"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="EffinitiveFramework.Core" Version="1.3.*" /> | ||
|
HBartosch marked this conversation as resolved.
Outdated
|
||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| using System.Text; | ||
| using EffinitiveFramework.Core; | ||
| using EffinitiveFramework.Core.Http; | ||
| using EffinitiveServer.Endpoints; | ||
|
HBartosch marked this conversation as resolved.
Outdated
|
||
|
|
||
| var port = args.Length > 0 && int.TryParse(args[0], out var p) ? p : 8080; | ||
|
|
||
| var app = EffinitiveApp | ||
| .Create() | ||
| .UsePort(port) | ||
| .MapEndpoints() | ||
| .Build(); | ||
|
|
||
| Console.WriteLine($"Effinitive listening on http://localhost:{port}"); | ||
| await app.RunAsync(); | ||
|
|
||
| namespace EffinitiveServer.Endpoints | ||
| { | ||
| // ── GET / ────────────────────────────────────────────────────── | ||
|
|
||
| sealed class GetRoot : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "GET"; | ||
| protected override string Route => "/"; | ||
| protected override string ContentType => Helpers.TextPlain; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult("OK"); | ||
| } | ||
|
|
||
| // ── POST / ───────────────────────────────────────────────────── | ||
|
|
||
| sealed class PostRoot : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "POST"; | ||
| protected override string Route => "/"; | ||
| protected override string ContentType => Helpers.TextPlain; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| { | ||
| var body = HttpContext?.Body; | ||
| return ValueTask.FromResult(body is { Length: > 0 } ? Encoding.UTF8.GetString(body) : ""); | ||
| } | ||
| } | ||
|
|
||
| // ── GET/POST /echo ──────────────────────────────────────────── | ||
|
|
||
| sealed class EchoGet : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "GET"; | ||
| protected override string Route => "/echo"; | ||
| protected override string ContentType => Helpers.TextPlain; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.EchoHeaders(HttpContext)); | ||
| } | ||
|
|
||
| sealed class EchoPost : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "POST"; | ||
| protected override string Route => "/echo"; | ||
| protected override string ContentType => Helpers.TextPlain; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.EchoHeaders(HttpContext)); | ||
| } | ||
|
|
||
| // ── GET/POST /cookie ────────────────────────────────────────── | ||
|
|
||
| sealed class CookieGet : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "GET"; | ||
| protected override string Route => "/cookie"; | ||
| protected override string ContentType => Helpers.TextPlain; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.ParseCookies(HttpContext)); | ||
| } | ||
|
|
||
| sealed class CookiePost : NoRequestEndpointBase<string> | ||
| { | ||
| protected override string Method => "POST"; | ||
| protected override string Route => "/cookie"; | ||
| protected override string ContentType => Helpers.TextPlain; | ||
|
|
||
| public override ValueTask<string> HandleAsync(CancellationToken ct = default) | ||
| => ValueTask.FromResult(Helpers.ParseCookies(HttpContext)); | ||
| } | ||
|
|
||
| // ── Shared helpers ──────────────────────────────────────────── | ||
|
|
||
| static class Helpers | ||
| { | ||
| public const string TextPlain = "text/plain"; | ||
|
|
||
| public static string EchoHeaders(HttpRequest? ctx) | ||
| { | ||
| if (ctx?.Headers is null) return ""; | ||
| var sb = new StringBuilder(); | ||
| foreach (var h in ctx.Headers) | ||
| sb.Append(h.Key).Append(": ").Append(h.Value).Append("\r\n"); | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| public static string ParseCookies(HttpRequest? ctx) | ||
| { | ||
| if (ctx is null) return ""; | ||
| var sb = new StringBuilder(); | ||
| foreach (var c in ctx.Cookies) | ||
| sb.Append(c.Key).Append('=').Append(c.Value).Append("\r\n"); | ||
| return sb.ToString(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"name": "Effinitive", "language": "C#"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.