giraffe-fsharp / Giraffe

A native functional ASP.NET Core web framework for F# developers.

Home Page:https://giraffe.wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RFC-compliant Content-Length handling for 1xx, 204 and 205 responses and CONNECT requests

retendo opened this issue · comments

Giraffe should make sure to not send non-RFC-compliant Content-Length headers.

Related Kestrel issue:
dotnet/aspnetcore#42956

Related Kestrel PR:
dotnet/aspnetcore#43103

Context:
Since .NET 7, Kestrel throws an exception if Giraffe tries to send a wrong Content-Length header. See PR above.
My server receives quite a few CONNECT requests that now always return 500.

We should probably fix it here in Line 345:

[<Extension>]
static member WriteBytesAsync (ctx : HttpContext, bytes : byte[]) =
task {
ctx.SetHttpHeader(HeaderNames.ContentLength, bytes.Length)
if ctx.Request.Method <> HttpMethods.Head then
do! ctx.Response.Body.WriteAsync(bytes, 0, bytes.Length)
return Some ctx
}

Thanks for the issue and PR!

Once we get the release process issues ironed out I'll be releasing this.