Recently we need to build some RESTful services that responded with JSON and to my surprise these responses are not compressed when I fired up Fiddler and check the Transformer tab.

After enabling Failed Request Tracing in IIS by going to IIS Manager > Web Site > Right Panel > Actions Configure > Failed Request Tracing.

On the same page with the Right Panel of "Actions", under the IIS area, click into Failed Request Tracing Rules.

From there, at the Right Panel, click "Add..." > Specify Content to Trace > All content(*) > Status code(s): type in "200" > Finish.

You should make sure no other request is hitting on the same server at the same time to minimize the logging file creation, which is based on request, if you only have one request when you turn this on, there should only be one fr000001.xml file created in %windir%\inetpub\logs\FailedReqLogFiles\W3SVC1, open that in Internat Explorer and click on Request Details > Search for Compression, expand the corresponding node > Mine says in the node dynamic compression > not success > no_matching_content_type.

So it seems that even though by default HTTP Compression is enabled in IIS 7.5, there are only 3 content types that IIS recognizes and will actually perform the compression.

You can check this in IIS Manager > YOUR_SERVER > Under Management section > Configuration Editor > Expand the system.webServer > httpCompression > dynamicTypes

When you have a RESTful service that serve JSON based response and you would like that to be gzip/compressed whenever client's request includes in the header "Accept-Encoding: gzip", you must update this list to include both mime types

application/json
application/json;
charset=utf-8


in the list, you can either start adding these 2 type in the editor itself or you can run a command line tool AppCmd.exe from %windir%\system32\inetsrv directory, the full command is

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost

Remember to apply your settings if you are using the GUI editor, I used the command line tool because this is the only one that will add the type along with the "Entry Path", adding through the GUI editor for some reason doesn't add any Entry Type, it still works but I just don't like missing anything.

Now, restart IIS and you can check again in Fiddler and Viola! Now it says GZIP Encoding. You can "Click here to transform" to see the data :)