WebClient with automatic decompression in C#

To reduce traffic loading it is often used compression.

You may read scientific investigation about it on
web.mit.edu – Data Compression Techniques for Urban Traffic Data
and more technic on
research.vtu.ac.in – Gateway Traffic Compression.

When you use WebClient in your WebAPI (or etc.) application, downloaded file be in “confused” format. To solve the issue improve web client like this:

using System;
using System.Net;

namespace App
    public class WebClientSpecial : WebClient
        protected override WebRequest GetWebRequest(Uri address)
            WebRequest req = base.GetWebRequest(address);
            if (req is HttpWebRequest)
                (req as HttpWebRequest).AutomaticDecompression = 
                  DecompressionMethods.Deflate | DecompressionMethods.GZip;
            return req;

The DecompressionMethods in HttpWebRequest can be seen on