Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never decalre reader with use on ctx.Request.Body #564

Open
xperiandri opened this issue Oct 26, 2023 · 4 comments
Open

Never decalre reader with use on ctx.Request.Body #564

xperiandri opened this issue Oct 26, 2023 · 4 comments

Comments

@xperiandri
Copy link

this

use reader = new StreamReader(ctx.Request.Body, Encoding.UTF8)

disposes body, because the reader disposes underlying stream.
Which must not be done in any case!

@64J0
Copy link
Member

64J0 commented Oct 26, 2023

I did not get it, what is the problem with disposing the request body after reading it?

@xperiandri
Copy link
Author

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.

@64J0
Copy link
Member

64J0 commented Oct 29, 2023

I see, thanks for the explanation. I agree then!

@Banashek
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants