Never decalre reader with `use` on `ctx.Request.Body`
this https://github.com/giraffe-fsharp/Giraffe/blob/6a364955f77609e9265c577ddd817c92fefe104c/src/Giraffe/HttpContextExtensions.fs#L197 disposes body, because the reader disposes underlying stream. Which must not be done in any case!
I did not get it, what is the problem with disposing the request body after reading it?
The problem is that Giraffe is not an owner of it. The owner of it is an appropriate ASP.NET core middleware. Giraffe must not dispose the stuff it is not owner of. It leads to unexpected behavior for the consumer.
I see, thanks for the explanation. I agree then!
Looks like the leaveOpen parameter could be specified to allow disposal of the StreamReader without disposing the underlying resource: doc reference
use reader = new StreamReader(ctx.Request.Body, Encoding.UTF8, leaveOpen = true)