Skip to content

Commit 3f72bd5

Browse files
authored
[F#/Oxpecker] Got rid of SpanJson as bringning no benefit. Disabled ReadyToRun (#9071)
1 parent 84b9953 commit 3f72bd5

File tree

4 files changed

+10
-32
lines changed

4 files changed

+10
-32
lines changed

frameworks/FSharp/oxpecker/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This includes tests for plaintext, json, and fortunes HTML serialization.
1919

2020
* [Oxpecker](https://github.com/Lanayx/Oxpecker)
2121
* [Dapper](https://github.com/DapperLib/Dapper)
22-
* [SpanJson](https://github.com/Tornhoof/SpanJson)
2322
* ASP.NET Core
2423

2524
## Paths & Source for Tests

frameworks/FSharp/oxpecker/oxpecker.dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ COPY src/App .
44
RUN dotnet publish -c Release -o out
55

66
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
7+
8+
ENV DOTNET_ReadyToRun 0
9+
710
ENV URLS http://+:8080
811

912
WORKDIR /app

frameworks/FSharp/oxpecker/src/App/App.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@
1414
<PackageReference Include="Dapper" Version="2.1.44" />
1515
<PackageReference Include="Oxpecker" Version="0.10.1" />
1616
<PackageReference Include="Npgsql" Version="8.0.3" />
17-
<PackageReference Include="SpanJson" Version="4.0.1" />
1817
</ItemGroup>
1918
</Project>

frameworks/FSharp/oxpecker/src/App/Program.fs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace App
22

33
open System
44
open System.Collections.Generic
5-
open System.Threading.Tasks
65
open Oxpecker
76

87
[<AutoOpen>]
@@ -60,6 +59,7 @@ module HttpHandlers =
6059
open Npgsql
6160
open System.Text
6261
open Microsoft.AspNetCore.Http
62+
open System.Text.Json
6363

6464
let private extra =
6565
{
@@ -169,56 +169,33 @@ module HttpHandlers =
169169
ctx.SetContentType("text/plain")
170170
ctx.WriteBytes(result)
171171

172+
let jsonSimple value : EndpointHandler =
173+
let options = JsonSerializerOptions(JsonSerializerDefaults.Web)
174+
fun ctx ->
175+
ctx.Response.WriteAsJsonAsync(value, options)
176+
172177
let endpoints =
173178
[|
174179
route "/plaintext" <| utf8Const "Hello, World!"
175-
route "/json"<| jsonChunked {| message = "Hello, World!" |}
180+
route "/json"<| jsonSimple {| message = "Hello, World!" |}
176181
route "/fortunes" fortunes
177182
route "/db" singleQuery
178183
route "/queries/{count?}" multipleQueries
179184
route "/updates/{count?}" multipleUpdates
180185
|]
181186

182-
183187
module Main =
184-
open SpanJson
185-
open Microsoft.AspNetCore.Http
186188
open Microsoft.AspNetCore.Builder
187-
open Microsoft.AspNetCore.Hosting
188189
open Microsoft.Extensions.DependencyInjection
189190
open Microsoft.Extensions.Hosting
190191
open Microsoft.Extensions.Logging
191-
open System.Buffers
192-
193-
type SpanJsonSerializer() =
194-
interface Serializers.IJsonSerializer with
195-
member this.Serialize(value, ctx, chunked) =
196-
ctx.Response.ContentType <- "application/json"
197-
if chunked then
198-
if ctx.Request.Method <> HttpMethods.Head then
199-
JsonSerializer.Generic.Utf8.SerializeAsync<_>(value, stream = ctx.Response.Body).AsTask()
200-
else
201-
Task.CompletedTask
202-
else
203-
task {
204-
let buffer = JsonSerializer.Generic.Utf8.SerializeToArrayPool<_>(value)
205-
ctx.Response.Headers.ContentLength <- buffer.Count
206-
if ctx.Request.Method <> HttpMethods.Head then
207-
do! ctx.Response.Body.WriteAsync(buffer)
208-
ArrayPool<byte>.Shared.Return(buffer.Array)
209-
else
210-
return ()
211-
}
212-
member this.Deserialize _ =
213-
failwith "Not implemented"
214192

215193
[<EntryPoint>]
216194
let main args =
217195
let builder = WebApplication.CreateBuilder(args)
218196
builder.Services
219197
.AddRouting()
220198
.AddOxpecker()
221-
.AddSingleton<Serializers.IJsonSerializer>(SpanJsonSerializer())
222199
|> ignore
223200
builder.Logging.ClearProviders() |> ignore
224201
let app = builder.Build()

0 commit comments

Comments
 (0)