Explorar o código

2009-05-16 Gonzalo Paniagua Javier <[email protected]>

	* HttpWebResponse.cs:
	* HttpWebRequest.cs: support automatic decompression of the response.
	Fixes bug #504391.



svn path=/trunk/mcs/; revision=134269
Gonzalo Paniagua Javier %!s(int64=16) %!d(string=hai) anos
pai
achega
d3637642f7

+ 7 - 0
mcs/class/System/System.Net/ChangeLog

@@ -1,3 +1,10 @@
+2009-05-16 Gonzalo Paniagua Javier <[email protected]>
+
+	* HttpWebResponse.cs:
+	* HttpWebRequest.cs: support automatic decompression of the response.
+	Fixes bug #504391.
+
+
 2009-05-11 Gonzalo Paniagua Javier <[email protected]>
 
 	* Dns.cs: made GetHostAddresses and friends internal for 1.x

+ 15 - 3
mcs/class/System/System.Net/HttpWebRequest.cs

@@ -98,6 +98,9 @@ namespace System.Net
 		object locker = new object ();
 		bool is_ntlm_auth;
 		bool finished_reading;
+#if NET_2_0
+		DecompressionMethods auto_decomp;
+#endif
 #if NET_1_1
 		int maxResponseHeadersLength;
 		static int defaultMaxResponseHeadersLength;
@@ -192,14 +195,14 @@ namespace System.Net
 			return new NotImplementedException ();
 		}
 		
-		[MonoTODO]
 		public DecompressionMethods AutomaticDecompression
 		{
 			get {
-				throw GetMustImplement ();
+				return auto_decomp;
 			}
 			set {
-				throw GetMustImplement ();
+				CheckRequestStarted ();
+				auto_decomp = value;
 			}
 		}
 #endif
@@ -1024,6 +1027,15 @@ namespace System.Net
 					webHeaders.SetInternal ("Cookie", cookieHeader);
 			}
 
+#if NET_2_0
+			string accept_encoding = null;
+			if ((auto_decomp & DecompressionMethods.GZip) != 0)
+				accept_encoding = "gzip";
+			if ((auto_decomp & DecompressionMethods.Deflate) != 0)
+				accept_encoding = accept_encoding != null ? "gzip, deflate" : "deflate";
+			if (accept_encoding != null)
+				webHeaders.SetInternal ("Accept-Encoding", accept_encoding);
+#endif
 			if (!usedPreAuth && preAuthenticate)
 				DoPreAuthenticate ();
 

+ 10 - 0
mcs/class/System/System.Net/HttpWebResponse.cs

@@ -39,6 +39,9 @@ using System.IO;
 using System.Net.Sockets;
 using System.Runtime.Serialization;
 using System.Text;
+#if NET_2_0
+using System.IO.Compression;
+#endif
 
 namespace System.Net 
 {
@@ -89,6 +92,13 @@ namespace System.Net
 				this.cookie_container = container;	
 				FillCookies ();
 			}
+#if NET_2_0
+			string content_encoding = webHeaders ["Content-Encoding"];
+			if (content_encoding == "gzip" && (data.request.AutomaticDecompression & DecompressionMethods.GZip) != 0)
+				stream = new GZipStream (stream, CompressionMode.Decompress);
+			else if (content_encoding == "deflate" && (data.request.AutomaticDecompression & DecompressionMethods.Deflate) != 0)
+				stream = new DeflateStream (stream, CompressionMode.Decompress);
+#endif
 		}
 
 #if NET_2_0