* HttpWebResponse.cs: Initialize contentLength in ctor, as it must
authorGert Driesen <drieseng@users.sourceforge.net>
Fri, 25 Jul 2008 18:42:53 +0000 (18:42 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Fri, 25 Jul 2008 18:42:53 +0000 (18:42 -0000)
remain accessible after the response is disposed (and the headers are
no longer available). Adding missing disposed checks in properties
(except for StatusCode) and GetResponseHeader. On the 2.0 profile,
headers must remain accessible after the HttpWebResponse is disposed.
* System_test.dll.sources: Added HttpWebResponseTest.cs.
* HttpWebResponseTest.cs: Enabled tests.

svn path=/trunk/mcs/; revision=108804

mcs/class/System/ChangeLog
mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/HttpWebResponse.cs
mcs/class/System/System_test.dll.sources
mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/HttpWebResponseTest.cs

index 37d8b47cf9abd316b6f939fcd22c5684381fd6f5..5fa9700825549329ae1dbb3fea758f9ab7fb651c 100644 (file)
@@ -1,3 +1,7 @@
+2008-07-25  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * System_test.dll.sources: Added HttpWebResponseTest.cs.
+
 2008-07-14  Marek Habersack  <mhabersack@novell.com>
 
        * System.dll.sources: added
index 195cd0b4f00e293ea98d206477f01008a5ad295f..a40214d9ab556190312a0a9532c91c8f1c13b216 100644 (file)
@@ -1,3 +1,11 @@
+2008-07-25  Gert Driesen  <drieseng@users.sourceforge.net>ยต
+
+       * HttpWebResponse.cs: Initialize contentLength in ctor, as it must
+       remain accessible after the response is disposed (and the headers are
+       no longer available). Adding missing disposed checks in properties
+       (except for StatusCode) and GetResponseHeader. On the 2.0 profile,
+       headers must remain accessible after the HttpWebResponse is disposed.
+
 2008-06-10  Stephane Delcroix  <sdelcroix@novell.com>
 
        * IPAddress.cs: allow usage on 2.1 as smcs knows nothing about
index d4866e30e12a4a346bb27a48d12c71dbc0c082c2..5ce6215dc8761ae056675ea86652e295c2b9644a 100644 (file)
@@ -52,11 +52,11 @@ namespace System.Net
                Version version;
                HttpStatusCode statusCode;
                string statusDescription;
-               long contentLength = -1;
+               long contentLength;
                string contentType;
                CookieContainer cookie_container;
 
-               bool disposed = false;
+               bool disposed;
                Stream stream;
                
                // Constructors
@@ -70,6 +70,13 @@ namespace System.Net
                        statusCode = (HttpStatusCode) data.StatusCode;
                        statusDescription = data.StatusDescription;
                        stream = data.stream;
+
+                       try {
+                               contentLength = (long) UInt64.Parse (webHeaders ["Content-Length"]);
+                       } catch (Exception) {
+                               contentLength = - 1;
+                       }
+
                        if (container != null) {
                                this.cookie_container = container;      
                                FillCookies ();
@@ -117,7 +124,8 @@ namespace System.Net
                }
                
                public string ContentEncoding {
-                       get { 
+                       get {
+                               CheckDisposed ();
                                string h = webHeaders ["Content-Encoding"];
                                return h != null ? h : "";
                        }
@@ -125,21 +133,14 @@ namespace System.Net
                
                public override long ContentLength {            
                        get {
-                               if (contentLength != -1)
-                                       return contentLength;
-
-                               try {
-                                       contentLength = (long) UInt64.Parse (webHeaders ["Content-Length"]); 
-                               } catch (Exception) {
-                                       return -1;
-                               }
-
                                return contentLength;
                        }
                }
                
                public override string ContentType {            
                        get {
+                               CheckDisposed ();
+
                                if (contentType == null)
                                        contentType = webHeaders ["Content-Type"];
 
@@ -148,18 +149,23 @@ namespace System.Net
                }
                
                public CookieCollection Cookies {
-                       get { 
+                       get {
+                               CheckDisposed ();
                                if (cookieCollection == null)
                                        cookieCollection = new CookieCollection ();
                                return cookieCollection;
                        }
                        set {
+                               CheckDisposed ();
                                cookieCollection = value;
                        }
                }
                
                public override WebHeaderCollection Headers {           
-                       get { 
+                       get {
+#if ONLY_1_1
+                               CheckDisposed ();
+#endif
                                return webHeaders; 
                        }
                }
@@ -181,6 +187,7 @@ namespace System.Net
                
                public DateTime LastModified {
                        get {
+                               CheckDisposed ();
                                try {
                                        string dtStr = webHeaders ["Last-Modified"];
                                        return MonoHttpDate.Parse (dtStr);
@@ -191,37 +198,42 @@ namespace System.Net
                }
                
                public string Method {
-                       get { 
+                       get {
+                               CheckDisposed ();
                                return method; 
                        }
                }
                
                public Version ProtocolVersion {
-                       get { 
+                       get {
+                               CheckDisposed ();
                                return version; 
                        }
                }
                
                public override Uri ResponseUri {               
-                       get { 
+                       get {
+                               CheckDisposed ();
                                return uri; 
                        }
                }               
                
                public string Server {
-                       get { 
+                       get {
+                               CheckDisposed ();
                                return webHeaders ["Server"]; 
                        }
                }
                
                public HttpStatusCode StatusCode {
-                       get { 
+                       get {
                                return statusCode; 
                        }
                }
                
                public string StatusDescription {
-                       get { 
+                       get {
+                               CheckDisposed ();
                                return statusDescription; 
                        }
                }
@@ -236,6 +248,7 @@ namespace System.Net
                
                public string GetResponseHeader (string headerName)
                {
+                       CheckDisposed ();
                        string value = webHeaders [headerName];
                        return (value != null) ? value : "";
                }
@@ -311,7 +324,9 @@ namespace System.Net
                        if (disposing) {
                                // release managed resources
                                uri = null;
+#if !NET_2_0
                                webHeaders = null;
+#endif
                                cookieCollection = null;
                                method = null;
                                version = null;
index 7f5b9bc708809179c4ba229e87e87858abc81c7f..6e19b7dc335e85a7028f03051ffb0cadcff0b207 100644 (file)
@@ -194,6 +194,7 @@ System.Net/DnsTest.cs
 System.Net/FileWebRequestTest.cs
 System.Net/FileWebResponseTest.cs
 System.Net/HttpWebRequestTest.cs
+System.Net/HttpWebResponseTest.cs
 System.Net/HttpListenerTest.cs
 System.Net/HttpListenerBasicIdentityTest.cs
 System.Net/HttpListenerPrefixCollectionTest.cs
index bb5143c44db77490d7e4b0f6b16c0a228c009fd4..4dd087b8575954d88f387f57b65b4d5f1adf8f70 100644 (file)
@@ -1,3 +1,7 @@
+2008-07-25  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * HttpWebResponseTest.cs: Enabled tests.
+
 2008-07-03  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * HttpListener2Test.cs: Added test for multiple responses.
index e74ef6e4927548718725b08093051faad4af6858..eba0377e59a699db49f9523b517be2a1c4c17028 100644 (file)
@@ -19,7 +19,6 @@ using NUnit.Framework;
 namespace MonoTests.System.Net
 {
        [TestFixture]
-       [Ignore ("Awaits approval of fixes")]
        public class HttpWebResponseTest
        {
                [Test]