ColdFusion - how to set Content-Length header

2019-05-02 11:21发布

Has anyone successfully added a Content-Length header to regular ColdFusion (I'm using CF9) pages? I'm setting up a new server behind a Cisco load balancer with compression - the box refuses to compress anything without this header, but CF doesn't pass it by default.

<cfheader name="Content-Length" value="something"> will set the header, but finding the right value is a problem.

Any pointers would be much appreciated.

2条回答
Evening l夕情丶
2楼-- · 2019-05-02 11:41

I believe I've solved it:

<cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#">

I stuck that in onRequestEnd() and the Cisco box is happily compressing away.

Thanks for the input folks.

查看更多
smile是对你的礼貌
3楼-- · 2019-05-02 11:53

I don't love this idea, but could you make some sort of wrapper with cfsavecontent and take the length of that?

Something like:

<cfsetting enablecfoutputonly="yes">
<cfsavecontent variable="testVar">
     <cfinclude template="myPage.cfm">
</cfsavecontent>
<cfheader name="Content-Length" value="#len(testVar)#">
<cfoutput>#testVar#</cfoutput>

I'm not sure if the count would be off due to white space issues.

查看更多
登录 后发表回答