2009-01-26 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 26 Jan 2009 06:44:21 +0000 (06:44 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 26 Jan 2009 06:44:21 +0000 (06:44 -0000)
* HttpWebResponse.cs: avoid throwing an exception when
Content-Length is not present.

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

mcs/class/System/System.Net/HttpWebResponse.cs

index 5ce6215dc8761ae056675ea86652e295c2b9644a..33028dd12f038cf598bc051eecc869f1956e0220 100644 (file)
@@ -70,11 +70,19 @@ namespace System.Net
                        statusCode = (HttpStatusCode) data.StatusCode;
                        statusDescription = data.StatusDescription;
                        stream = data.stream;
+                       contentLength = -1;
 
                        try {
-                               contentLength = (long) UInt64.Parse (webHeaders ["Content-Length"]);
+                               string cl = webHeaders ["Content-Length"];
+#if NET_2_0
+                               if (String.IsNullOrEmpty (cl) || !Int64.TryParse (cl, out contentLength))
+                                       contentLength = -1;
+#else
+                               if (cl != null && cl != String.Empty)
+                                       contentLength = (long) UInt64.Parse (cl);
+#endif
                        } catch (Exception) {
-                               contentLength = - 1;
+                               contentLength = -1;
                        }
 
                        if (container != null) {