-
Notifications
You must be signed in to change notification settings - Fork 195
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
HttpRequestData.Body cannot be read more than once. #2957
Comments
Experiencing the same issue here. Makes trying to do some custom auth work a bit annoying! |
Referencing existing closed issue: #1911 |
Thanks for the reference for the temporary fix but that cannot be the real long term solution. This feels like a bug of some kind. |
I can confirm the same If I remove this package and switch to using the
And then using the following code in my middleware:
I can read the body and reset the stream without issues. Then in my
|
The difference between using the .NET Core integration package or not in this case is the implementation of |
Looks like the implementation utilizes the base abstract Stream and when executing it is of type https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestStream.cs which does not have those methods implemented. |
When using the .NET Core integration the HttpRequestData.Body property is unabled to be read more than once.
Since the stream has "CanSeek" set to false, we cannot reset its position before the HTTP Trigger picks up the request.
I'm unsure if this is intended or not, but it means that it is impossible to read the request body in a middleware, and also process the request in the function itself. This works as expected when not using the .NET Core integration.
There seems to be a different implementation of HttpRequestData, AspNetCoreHttpRequestData when using the .NET Core integration, and GrpcHttpRequestData when using the normal worker.
Repository to reproduce the issue: https://github.com/rustichowie/AzureFunction.StreamReadBug
Repro steps
Expected behavior
Expected behavior is for this to work without throwing an exception.
Actual behavior
Setting the position of the stream back to zero causes an NotSupportedException to be thrown.
The text was updated successfully, but these errors were encountered: