Azure / azure-functions-dotnet-worker

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

Behavioural changes when using request body as the request content for a chained http request #2646

Open Mrnikbobjeff opened 1 month ago

Mrnikbobjeff commented 1 month ago

Description

We have a C# function app calling a Java function app. The C# function app received a request and is supposed to just use the request body as the content for the HttpRequest towards the Java function. While this works in .NET 8 non isolated worker model functions, in dotnet-isolated the request body appears to be empty on the Java function side. This only occurs with some webservers. Reading the entire HttpRequest in the C# Function and passing it on as a StringContent "fixes" this behaviour, though now one would have to read every request body into a string, which is not what we want when uploading large json files. It also does not seem only Stream related, as a FileStream which is read in the function can be passed as StreamContent to a backend service.I have attached a minimum repro, I can provide the confidential request url if needed.

TestJasper.zip

Steps to reproduce

Try to send a HttpRequestData Body via a new HttpRequestMessage as Content fails on dotnet-isolated

Educated guesses

HttpRequest.Body implementation of the Stream type changed from https://github.com/dotnet/aspnetcore/blob/main/src/Http/WebUtilities/src/FileBufferingReadStream.cs to https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestStream.cs when migration in-process-> dotnet isolated

Mrnikbobjeff commented 1 month ago

I managed to isolate it further. transfer-encoding is set to chunked in the dotnet-isolated worker runtime. This causes issues when calling a java function host. Setup an ngrok instance, run the aforementioned code against your ngrok and you see the difference between the requests.