Azure / Azure/azure-functions-dotnet-worker
HttpRequestData.Body cannot be read more than once.
- Dominant language
- C#
- Stars
- 466
- Forks
- 215
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 7
Description
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
1. Create a new Azure Function using the default template
2. Add a simple middleware that reads from the request body and reset the stream position back to zero.
3. Add a HTTP Trigger that also tries to read from the same request body
#### 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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing the AspNetCoreHttpRequestData and GrpcHttpRequestData implementations of HttpRequestData, focusing on how Body is exposed and whether the stream can be rewound. Use the linked AzureFunction.StreamReadBug repository and the listed middleware-to-HTTP-trigger reproduction to verify the behavior. Done means the request body can be read in middleware and then by the function without a NotSupportedException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100