nContentLength

Defines the response buffer length prior to compression (if any).

Syntax

Response.nContentLength = nSize

Note

The default value of Response.nContentLength is NIL. In this case the current size of the response buffer at the moment of transmission will be used. This value needs only to be changed if the response buffer size is altered through encoding. In such a case a mandatory Content-Encoding header must be sent to inform the browser of the encoding used.

In any request, the browser will indicate the encoding supported by it in an HTTP_ACCEPT header; this header is available in the AFP page as a server variable. As a rule, all modern browsers from Internet Explorer 4.x upwards support data compression through the gzip algorithm, which typically achieves a compression ratio of 50%-70% for HTML pages. Compressing responses saves bandwidth and accelerates communication. AFP documents can be compressed with the aid of the following code in the corresponding .code file:

PROCEDURE Event_PageAfter

   Local lcFLL , lcCompressed

   IF "gzip" $ LOWER(Request.ServerVariables("HTTP_ACCEPT"))

     lcFLL = Path.MakePath("%root%\foxcrypto.fll")

     SET LIBRARY TO (m.lcFLL)

     Response.nContentLength = LEN(Response.Body())

     lcCompressed = GZip( Response.Body(), 1 )

     Response.Clear()

     Response.BinaryWrite( m.lcCompressed )

     Response.AddHeader( "Content-Encoding", "gzip")

   ENDIF

ENDPROC

For this sample, FoxCrypto.FLL must be located in the AFP program directory. The library is available at http://www.connectthenet.com/foxpro/FoxCrypto.fll.

See also

Response.ContentType