Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
432 stars 184 forks source link

HTTP body conversion will throw an InvalidOperationException when the request have an empty body #2516

Open Tri125 opened 5 months ago

Tri125 commented 5 months ago

Description

HTTP body conversion will throw an InvalidOperationException when the request have an empty body.

With the built-in HTTP type I have traced the origin of the issue(s) back to this line of the DefaultFromBodyConversionFeature.

Steps to reproduce

This repository has been made available to demonstrate the issue.

Debug each project one by one and send all 3 request to them :

curl -d '{ "Name": "potato" }' -H "Content-Type: application/json" -X POST http://localhost:7021/api/Function1 -v

curl -H "Content-Type: application/json" -X POST http://localhost:7021/api/Function1 -v

curl -X POST http://localhost:7021/api/Function1 -v

This will demonstrate the issues and the difference in behavior between them.

The latest version of the packages have been used :

    Microsoft.Azure.Core.NewtonsoftJson v2.0.0
    Microsoft.Azure.Functions.Worker v1.22.0
    Microsoft.Azure.Functions.Worker.Extensions.Http v3.2.0
    Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore v1.3.1
    Microsoft.Azure.Functions.Worker.Sdk v1.17.2
Tri125 commented 4 months ago

Specifically for the case when a response is never sent back to the client, it was fixed in v1.3.2. It was related to #2476.