Azure / Azure/azure-functions-host
Azure Functions v3 HttpTrigger: request body is empty
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
HttpTrigger works incorrectly in the following conditions:
* Azure Functions v3
* TargetFramework: netcoreapp3.1
* `Microsoft.NET.Sdk.Functions` version `3.0.2`
* Code:
```
[FunctionName("RunNetCore3")]
public static async Task RunNetCore3Async(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "netcore3/{id}")]
CustomRouteParameter parameter,
HttpRequest request,
CancellationToken cancellationToken)
{
using (var reader = new StreamReader(request.Body, Encoding.UTF8))
{
return await reader.ReadToEndAsync();
}
}
```
* The request body in the `request` variable is empty if request contains `Content-Type: application/json` header (works ok with any other `Content-Type` values except `application/json`). So in the example the empty response body will be returned which is unexpected.
#### Investigative information
I've created the [repository](https://github.com/myarotskaya/AzureFunctions.NetCore3.Bug) to demonstrate this issue. The source code of this repository is deployed to the Function App.
- Timestamp: 09:27 AM (UTC Time)
- Function App version: 3.0
- Function App name: NetCore3HttpBindingBug
- Function name(s) (as appropriate): RunNetCore3
- Invocation ID: `32894c31-74ac-4a98-8f94-fe6c76662d7d`
- Region: Central US
#### Repro steps
* Send `POST https://netcore3httpbindingbug.azurewebsites.net/api/netcore3/qqq` request with some body and `Content-Type: application/json` header.
#### Expected behavior
Request's body is returned in the response.
#### Actual behavior
Request's body is not returned in the response.
#### Known workarounds
Do not send `Content-Type: application/json` header or send any other value in the `Content-Type` header.
#### Related information
The same code works correct in Azure Functions v2 on netcoreapp2.1 with `Microsoft.NET.Sdk.Functions` version `1.0.29` and in ASP.NET Core 3.1 Web Application.
There are two endpoints to check it (see the [repository](https://github.com/myarotskaya/AzureFunctions.NetCore3.Bug)):
* Send `POST /netcore2/some-id` request with some body and `Content-Type: application/json` header
* Send `POST /aspnetcore3/some-id` request with some body and `Content-Type: application/json` header
In both cases the request body will be returned in the response (I didn't deploy it to any Function App but it's reproducible locally as well).
Contributor guide
Assessment
This issue has not been assessed yet.