Skip to content

Commit

Permalink
Update to GenHTTP 9.6 and switch to basic handler (#8190)
Browse files Browse the repository at this point in the history
* Update to GenHTTP 9.6 and switch to basic handler

* Switch package references to wildcard on bugfix level

Co-authored-by: Marwan Rabbâa <[email protected]>

---------

Co-authored-by: Marwan Rabbâa <[email protected]>
  • Loading branch information
Kaliumhexacyanoferrat and waghanza authored Jan 28, 2025
1 parent 0b74478 commit 484339a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
51 changes: 51 additions & 0 deletions csharp/genhttp/BenchmarkHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using GenHTTP.Api.Content;
using GenHTTP.Api.Protocol;

using Strings = GenHTTP.Modules.IO.Strings;

namespace web;

internal class BenchmarkHandler : IHandler
{
private static readonly FlexibleContentType _TextType = FlexibleContentType.Get(ContentType.TextPlain);

private static readonly Strings.StringContent _EmptyContent = new("");

public ValueTask PrepareAsync() => new();

public ValueTask<IResponse> HandleAsync(IRequest request)
{
IResponse response = null;

var target = request.Target;

if (target.Ended)
{
response = GetEmptyResponse(request);
}
else if (target.Current.Original == "user")
{
target.Advance();

if (target.Ended)
{
response = GetEmptyResponse(request);
}
else
{
response = GetEmptyResponse(request, new Strings.StringContent(target.Current.Original));
}
}

return new(response);
}

private static IResponse GetEmptyResponse(IRequest request, Strings.StringContent content = null)
{
return request.Respond()
.Type(_TextType)
.Content(content ?? _EmptyContent)
.Build();
}

}
10 changes: 3 additions & 7 deletions csharp/genhttp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using GenHTTP.Engine.Kestrel;
using GenHTTP.Modules.Functional;
using GenHTTP.Engine.Internal;

var empty = "";
using web;

var app = Inline.Create()
.Get(() => empty)
.Get("/user/:id", (string id) => id)
.Post("/user", () => empty);
var app = new BenchmarkHandler();

return await Host.Create()
.Handler(app)
Expand Down
2 changes: 1 addition & 1 deletion csharp/genhttp/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
framework:
github: Kaliumhexacyanoferrat/GenHTTP
version: 9.4
version: 9.6
3 changes: 1 addition & 2 deletions csharp/genhttp/web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GenHTTP.Core.Kestrel" Version="9.5.0" />
<PackageReference Include="GenHTTP.Modules.Functional" Version="9.5.0" />
<PackageReference Include="GenHTTP.Core" Version="9.6.*" />
</ItemGroup>

</Project>

0 comments on commit 484339a

Please sign in to comment.