dotMorten

A more efficient webclient for .NET

Mar 12th, 2012
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System.Net;
  2. using System.Net.Cache;
  3. using System;
  4.  
  5. namespace SharpGIS
  6. {
  7.     /// <summary>
  8.     /// A more efficient WebClient for .NET.
  9.     /// Automatically uses GZIP/Deflate if the server supports it
  10.     /// and caches responses if the server response contains a cache-
  11.     /// header (ie. 'expires' or 'ETag').
  12.     /// </summary>
  13.     public class GZipWebClient : WebClient
  14.     {
  15.         public GZipWebClient()
  16.         {
  17.             //Use the browser cache if the server tells us the response is cacheable
  18.             CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default);
  19.         }
  20.         protected override System.Net.WebRequest GetWebRequest(Uri address)
  21.         {
  22.             System.Net.WebRequest wr = base.GetWebRequest(address);
  23.             //Support GZIP and Deflate compressed responses from server
  24.             ((HttpWebRequest)wr).AutomaticDecompression =
  25.                 DecompressionMethods.GZip | DecompressionMethods.Deflate;
  26.             return wr;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment