Tuesday, November 27, 2007

Handling content compression with CFHTTP

Lots of web servers return compressed pages for faster delivery of pages. Our browsers happily decompress these pages on the fly and show them up. However, when using CFHTTP to get content from URLs if the server returns compressed content your in a bit of trouble.

The solution is easy: provide a HTTP header directive that specifies that your request does not accept compression and the web server should honor that by giving uncompressed content. To do this, your CFHTTP statement should look like:

resolveurl = Yes
throwonerror = Yes >
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">

No comments: