Empty response in post-flow policy for transfer-encoding: chunked

I have Apigee X proxies in front of some target servers returning the response as transfer-encoding: chunked. I have response.streaming set to false for the target endpoints. I try to read the contents of the response (response.content) in Javascript / AssignMessage/ExtractVariables policy. Unfortunately most of the time it returns empty response. It happens with the servers provided by multiple vendors so I don’t suspect the problem on the target server side. At times (rarely) it actually works fine so it looks like race-condition - the data is not fully buffered before Apigee proceeds to post-flow policies. Any hints?

Hi @tomekem_yh, welcome to the Apigee forums! We are incredibly excited to have you join our community :rocket:

We encourage our community members and experts to chime in with their knowledge and hints for your setup, we wanted to make sure you have some resources to look over in the meantime, you might find our community resources valuable:

You are also invited to join our Community Techtalks; we’re hosting a session this Thursday, May 28, covering the Apigee Production Go-Live Checklist. It’s happening at 5 PM CEST | 11 AM EDT. Please register here—we would love to have you there!

Hi @tomekem_yh - thanks for reaching out, the only way to work with streaming payloads is to use the EventStream feature, see docs here: Streaming server-sent events  |  Apigee  |  Google Cloud Documentation.

Per my understanding, there are 2 types of streaming:

  • “Content-type: text/event-stream” - handled by event stream in Apigee
  • “Transfer-encoding: chunked” - not handled by event stream in Apigee but like regular response

Is it correct?

Yes that’s correct, EventFlow just handles SSE text/event-stream.

So what is Apigee recommendation for buffering of “Transfer-encoding: chunked” response?

I ran into something very similar while working with response.streaming=false as well in my case, response.content was occasionally empty in the post-flow even though the backend returned a valid chunked response. Did you ever find out whether this was related to buffering timing in Apigee X, or was there another workaround that made it more reliable?

I’m trying to determine if the behaviour that I observe is a defect or it is simply not supported by Apigee. Per my understanding of Apigee specification, it should work.

If you have response.streaming.enabled set to false, then the chunked response should get buffered and be available in javascript in response.content. It could be that your target is doing something unusual in writing the chunked data, and that’s why it’s not getting buffered correctly. Do you have a public target endpoint that I can test with where it’s not working?