Some status codes like 101 do not allow a response body, or even declaring Content-Length: 0. Kestrel will throw in these scenarios.
System.InvalidOperationException: Response Content-Length mismatch: too many bytes written (90 of 0).
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.VerifyAndUpdateWrite(Int32 count)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WritePipeAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpUpgradeStream.WriteAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)
at Yarp.ReverseProxy.Forwarder.StreamCopier.CopyAsync(Stream input, Stream output, Int64 promisedContentLength, StreamCopierTelemetry telemetry, ActivityCancellationTokenSource activityToken, CancellationToken cancellation)
YARP should remove Content-Length: 0 from such responses to mitigate misbehaving destination servers.
Also check 204, etc.
See dotnet/aspnetcore#40882 (comment)
Some status codes like 101 do not allow a response body, or even declaring
Content-Length: 0. Kestrel will throw in these scenarios.YARP should remove
Content-Length: 0from such responses to mitigate misbehaving destination servers.Also check 204, etc.
See dotnet/aspnetcore#40882 (comment)