unable to set Content-Length header at apigee layer, it seems to be populated and is visible in trace but is not visible in final response.

please find the details as below:

JS Script:

try { var body= context.getVariable('response.content'); var noBytes= (unescape(encodeURIComponent((body)))).length; // context.setVariable("request.header.content-length",req.length); context.setVariable('response.header.Content-Length', noBytes); print("The header is :"+noBytes); } catch(Error){ print("Error " + Error); context.setVariable('JS_Error', true); throw new Error("JS_Error"); }

Assign message:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="xxxx"> <DisplayName>xxxx</DisplayName> <Set> <Headers> <Header name="X-RateLimit-Available-Count">{ratelimit.EnforceQuota.available.count}</Header> <Header name="X-RateLimit-Allowed-Count">{ratelimit.EnforceQuota.allowed.count}</Header> <Header name="X-RateLimit-Reset-Time">{ratelimit.EnforceQuota.expiry.time}</Header> <Header name="Content-Length">{response.header.content-length}</Header> </Headers> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="response"/> </AssignMessage>

0 3 1,493
3 REPLIES 3

With that AssignMessage policy, it seems that in part, you are assigning the value of the Content-Length header to the Content-Length header. In other words you are assigning X to X. What is the point of that? What is your goal there? I see that you're assigning to other headers, and that makes sense to me (the ratelimit headers). I don't understand what you want to accomplish wby assigning the value of a header to that same header.

Second thing - you probably don't need to set the Content-Length header of the response at all. Apigee should take care of that for you. Why do you think you need to set it explicitly?

Third - can you explain what you mean by

it seems to be populated ... but is not visible in final response.

Fourth - If you are certain of this claim, Can you give me a working API Proxy that exhibits this behavior? Specifically the behavior in which there is a content in the response, and the content-length header is not present in the response (and also Transfer-Encoding is not "Chunked". If Transfer-Encoding is Chunked there will be no content-length header; this is by design and in order to comply with the HTTP specification.).

hi @Dino-at-Google,

good day.

please find the proxy bundle and screenshot attached herewith.

hope this gives a better idea.9543-screenshot-2019-12-30-at-115438-am.png

9542-screenshot-2019-12-30-at-115817-am.png

9544-screenshot-2019-12-30-at-115956-am.png

http-bin-content-length.zip

Thanks in advance!

Content-Length header is auto-populated by apigee. I have never seen any manipulation of content-length response header unless you have a requirement (which is truly an anti-pattern).