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 ![]()
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:
-
Community Tech Talk: JS Policies from Basic to Advanced with SDLC
-
Community Tech Talk: Apigee Monitoring & Advanced Alerting
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?
I have seen it with Glean and Grafana MCP servers. Unfortunately none of them has public access to my knowledge.
I have seen similar behaviour in my setup where proxy.response.streaming.enabled = false but still the response body is not buffered. My use case is to buffer the streaming body and extract out meaningful data altogether instead of chunks.
Even if i use eventflow, I’d need to buffer the whole body via js which beats the whole purpose of eventflows.
This does sound more like a buffering/timing issue in the proxy flow than something specific to the target servers, especially since it happens with multiple vendors and occasionally works as expected.
One thing I’d check is whether response.streaming=false actually guarantees that the complete chunked response is available to post-flow policies at the point where you’re reading response.content. It may be worth checking the response state immediately before the JavaScript/AssignMessage policy and comparing it with cases where it works.
Also, if the target response is large or arrives in multiple chunks, I’d verify whether any other policy in the flow is modifying or consuming the response before you try to read it.
Has anyone seen this with Apigee X specifically when the target uses Transfer-Encoding: chunked? It would be useful to know whether there is a recommended way to explicitly force the target response to be fully buffered before post-flow processing.
i tried putting a custom.js file on every flow hook to extract and analyse the response.content and message.content variables. Turns out, response is sent over before streaming even ends, even after disabling streaming.
Here’s a summary from claude for debug.json file
- PostTarget flow hook (
TraceableJS):message.contentempty. - TargetEndpoint response PostFlow: both variables present but 0 bytes.
- ProxyEndpoint response PostFlow: both variables present but 0 bytes.
- PostProxy flow hook: body still empty.
- Response headers consistently show
Transfer-Encoding: chunkedandContent-Type: text/event-stream. - All streaming configuration is
false; EventFlow is disabled.
The timing proves the cause:
- Response processing reaches
RESP_SENTat06:46:43.900. - The SSE exchange continues until
06:46:44.974.
Therefore Apigee starts response policies and sends headers roughly one second before the finite stream completes. response.streaming.enabled=false is not causing this SSE response to be fully buffered.
I am trying this out on apigee cloud
"runtimeType": "CLOUD",
"subscriptionType": "TRIAL",
"state": "ACTIVE"