One of the key requirements for response body rewrite is that the response is not served by the origin server in a chunked format or compressed. In a previous topic I discussed how to prevent a server from serving a compressed response; in this topic I will discuss chunking.
Chunked transfer encoding is a method that a web server uses when the content being generated is dynamic and the server can't know how much data is being sent before starting to send it. As such, it sends a response header saying the content will be chunked, and in the first bytes of the body, it tells the size of the first "chunk" it is sending that it already knows about. Each chunk of data is followed by a new header that tells how much more data is following, until a chunk size of "0" is specified which tells the browser that no more data is following. Certain features that can be enabled on the NetScaler do not operate when chunking occurs on the response, including HTML Injection and body rewrite. The following policy will prevent chunking from occurring by changing the request HTTP version to HTTP 1.0, which per RFC will disable chunking on the response as a global policy. As a side note, the NetScaler will ALWAYS insert a connection keepalive header and assume that the server will maintain a persistent connection unless it specifies a connection close header in the response (per RFC).
add rewrite action req_http10 replace http.req.version "\"HTTP/1.0\""
add rewrite policy req_http10 true req_http10
bind rewrite global req_http10 20 NEXT -type REQ_DEFAULT
Tested on Release 8.1, build 32.1 (beta), but should operate on any release from 7.0+.