Capturing Response size with response streaming ON

Observing from TRACE tab, I see endpoint A returns with Content-length, endpoint B returns with Transfer-Encoding set to chunked in response header. For both endpoints, I can get Average of response size and Maximum of response size in my report. Therefore, somehow Apigee must be calculating response size even though endpoint B does not return Content-length. How can I access the response sizes, which Apigee calculates, from Apigee policy (for example JavaScript policy)?

Note: Although we enabled response streaming, I understand it is not relevant.

Solved Solved
0 3 587
1 ACCEPTED SOLUTION

I see. ok that's clear.

You can use MessageWeight element within the Quota policy to change the "weight" of a given API call.  But ... you need to have the payload size available, at the time of the execution of the Quota policy, in order to specify that MessageWeight.

I don't know a way to solve it completely when you have streaming and transfer-encoding "Chunked".  A possible escape is to .... unset streaming, and remove the chunked encoding... That would allow your proxy in the response flow to "see" the actual content-length.  (Basically use a JS step and evaluate context.getVariable('response.content').length ) and then use THAT as the MessageWeight. 

But if you are streaming and/or chunking, then I don't see a way to do it. 

The actual size that you see in the analytics record is not available at the time the Quota policy would execute, in the proxy response flow.  

View solution in original post

3 REPLIES 3

As far as I know there is no way to access that information from within a JS policy. 

In the case of response streaming, with Chunked Encoding, the response is sent back to the client AFTER any JS policy is executed within the proxy. 

What are you really trying to do? 

Thanks for your feedback!

What we are trying to achieve is response size base throttling. For example, if the total response size of calls made within one minute exceed 50 MB, Quota policy stops further calls. Something like that.

I see. ok that's clear.

You can use MessageWeight element within the Quota policy to change the "weight" of a given API call.  But ... you need to have the payload size available, at the time of the execution of the Quota policy, in order to specify that MessageWeight.

I don't know a way to solve it completely when you have streaming and transfer-encoding "Chunked".  A possible escape is to .... unset streaming, and remove the chunked encoding... That would allow your proxy in the response flow to "see" the actual content-length.  (Basically use a JS step and evaluate context.getVariable('response.content').length ) and then use THAT as the MessageWeight. 

But if you are streaming and/or chunking, then I don't see a way to do it. 

The actual size that you see in the analytics record is not available at the time the Quota policy would execute, in the proxy response flow.