5

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.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Geoff
  • 51
  • 1
  • 2
  • I don't know if you have control over the load balancer, but I believe that the default configuration of cisco load balancers is that it only compresses content over 512 bytes in length. But, this is a configuration value (minimum-size in the compression settings), and can be changed, and I'm pretty sure it can be changed to just compress everything (with the proper accepts header on the request, obv.) – Edward M Smith Oct 14 '10 at 16:02

2 Answers2

2

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.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Geoff
  • 21
  • 1
0

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.

Max
  • 191
  • 1
  • 2
  • 11