Skip to content

Commit 51a63ae

Browse files
[csharp] Update to GenHTTP 9.6 and use a regular handler for JSON (#9568)
* Update to GenHTTP 9.6 and use a regular handler for JSON * Use the same .NET optimizations as everyone elese * Update to 9.6.2
1 parent 3c1f933 commit 51a63ae

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<None Remove="Resources\Fortunes.html"/>
20-
<None Remove="Resources\Template.html"/>
19+
<None Remove="Resources\Fortunes.html" />
20+
<None Remove="Resources\Template.html" />
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<EmbeddedResource Include="Resources\Template.html"/>
24+
<EmbeddedResource Include="Resources\Template.html" />
2525
</ItemGroup>
2626

2727
<ItemGroup>
2828

29-
<PackageReference Include="GenHTTP.Core.Kestrel" Version="9.0.0" />
30-
<PackageReference Include="GenHTTP.Modules.Razor" Version="8.6.0" />
31-
<PackageReference Include="GenHTTP.Modules.Webservices" Version="9.0.0" />
29+
<PackageReference Include="GenHTTP.Core" Version="9.6.2" />
30+
<PackageReference Include="GenHTTP.Modules.Webservices" Version="9.6.2" />
3231

33-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
34-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
32+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
33+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
3534

3635
</ItemGroup>
3736

frameworks/CSharp/genhttp/Benchmarks/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
using Benchmarks.Tests;
22
using Benchmarks.Utilities;
3-
using GenHTTP.Engine.Kestrel;
3+
4+
using GenHTTP.Engine.Internal;
5+
46
using GenHTTP.Modules.IO;
57
using GenHTTP.Modules.Layouting;
68
using GenHTTP.Modules.Webservices;
79

810
var tests = Layout.Create()
911
.Add("plaintext", Content.From(Resource.FromString("Hello, World!")))
12+
.Add("json", new JsonHandler())
1013
.Add("fortunes", new FortuneHandler())
11-
.AddService<JsonResource>("json")
1214
.AddService<DbResource>("db")
1315
.AddService<QueryResource>("queries")
1416
.AddService<UpdateResource>("updates")
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Text.Json;
2+
3+
using GenHTTP.Api.Content;
4+
using GenHTTP.Api.Protocol;
5+
6+
using GenHTTP.Modules.Conversion.Serializers.Json;
7+
8+
namespace Benchmarks.Tests;
9+
10+
public sealed class JsonResult
11+
{
12+
13+
public string Message { get; set; }
14+
}
15+
16+
public sealed class JsonHandler : IHandler
17+
{
18+
private static readonly FlexibleContentType _ContentType = new(ContentType.ApplicationJson, "utf-8");
19+
20+
private static readonly JsonSerializerOptions _Options = new();
21+
22+
public ValueTask PrepareAsync() => new();
23+
24+
public ValueTask<IResponse> HandleAsync(IRequest request)
25+
{
26+
var result = new JsonResult()
27+
{
28+
Message = "Hello, World!"
29+
};
30+
31+
var response = request.Respond()
32+
.Content(new JsonContent(result, _Options))
33+
.Type(_ContentType)
34+
.Build();
35+
36+
return new(response);
37+
}
38+
39+
}

frameworks/CSharp/genhttp/Benchmarks/Tests/JsonResource.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

frameworks/CSharp/genhttp/genhttp.dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore --self-cont
1111

1212
# final stage/image
1313
FROM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine
14+
15+
ENV DOTNET_GCDynamicAdaptationMode=0
16+
ENV DOTNET_ReadyToRun=0
17+
ENV DOTNET_HillClimbing_Disable=1
18+
1419
WORKDIR /app
1520
COPY --from=build /app .
1621

0 commit comments

Comments
 (0)