Skip to content
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

Update to GenHTTP 9.6 and switch to basic handler #8190

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0" />
Kaliumhexacyanoferrat marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

</Project>
Loading