azure-functions-java-worker
azure-functions-java-worker copied to clipboard
Http Requests with Transfer-Encoding: chunked report an empty body
Sending requests to a Java HttpTriggered function results in an empty body if transfer-encoding is set to chunked
Investigative information
Please provide the following:
- Timestamp: local
- Function App name: HttpTriggerJava
- Function name(s) (as appropriate): -
- Invocation ID: -
- Region: -
Repro steps
Provide the steps required to reproduce the problem:
- Send a http request which does not contain content-length but uses a transfer-encoding: chunked style of sending data
- The function app fails to read the request body
Expected behavior
transfer-encoding: chunked works as expected
Actual behavior
The request body is empty
Known workarounds
provide the content-length client side by reading the entire request into memory. Not viable as a proxy service where we ourselves get chunked requests.
Related information
Provide any related information
- Programming language used: Java & C# as a POC to call with the correct headers
package org.example.functions;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Stream;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
/**
* Azure Functions with HTTP Trigger.
*/
public class HttpTriggerJava {
/**
* This function listens at endpoint "/api/HttpTriggerJava". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpTriggerJava
* 2. curl {your host}/api/HttpTriggerJava?name=HTTP%20Query
*/
@FunctionName("HttpTriggerJava")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) throws Exception {
context.getLogger().info("Java HTTP trigger processed a request.");
//
return request.createResponseBuilder(HttpStatus.OK).body("Hello").build();
}
}
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Threading;
using System.Net.Http;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
namespace FunctionApp1
{
public class Function1
{
[Function("Function1")]
public async Task<IActionResult> GeneratePdfAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "documents/{tenant}/{engine}/{template}")] HttpRequestData req,
string engine,
string tenant,
string template,
CancellationToken ct)
{
using var client = new HttpClient() { BaseAddress = new Uri("http://localhost:50251/api/HttpTriggerJava") };
using var request = new HttpRequestMessage()
{
Method = HttpMethod.Post
};
//request.Content = new StringContent(await (new StreamReader(pdfRequest.Payload)).ReadToEndAsync());
request.Content = new StreamContent(req.Body);
request.Content.Headers.Add("Content-Type", "application/octet-stream");
using var response = await client.SendAsync(request, ct);
if (response.StatusCode == HttpStatusCode.OK)
return new FileStreamResult(await response.Content.ReadAsStreamAsync(ct), "application/pdf");
else
return new BadRequestObjectResult(await response.Content.ReadAsStringAsync());
}
}
}
Is anyone looking at this? Would prefer not having to switch to C#, since that seems to be the only implementation that works at the moment.
thanks for reporting, this is not currently supported in java function, we will be working on this. Currently node, python and c# functions support http streaming.
hello, any update on this? Do you plan to implement http streaming support in java functions?
Hey @turbostevek, yes. We expect to start working on it next month.
Hi, do you have any news on this topic? We face the same issue for a java based function and unfortunately our client cannot change the api.