Never decalre reader with `use` on `ctx.Request.Body`
xperiandri opened this issue · comments
this
Giraffe/src/Giraffe/HttpContextExtensions.fs
Line 197 in 6a36495
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)