Skip to content

HttpRequestData.Body cannot be read more than once. #10800

Open
@rustichowie

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.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions