[System] HttpListenerRequest: ignore bad cookies and keep request alive (#5657)
[mono.git] / mcs / class / System / System.Net / HttpListenerRequest.cs
index a9c5bb9ee32bb7e7a7208fb5ff68081f11a143de..e351807aa3befe092968fe95930f0c1820320e00 100644 (file)
@@ -28,8 +28,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if SECURITY_DEP
-
 using System.Collections;
 using System.Collections.Specialized;
 using System.Globalization;
@@ -332,16 +330,20 @@ namespace System.Net {
                                                        if (current != null) {
                                                                cookies.Add (current);
                                                        }
-                                                       current = new Cookie ();
-                                                       int idx = str.IndexOf ('=');
-                                                       if (idx > 0) {
-                                                               current.Name = str.Substring (0, idx).Trim ();
-                                                               current.Value =  str.Substring (idx + 1).Trim ();
-                                                       } else {
-                                                               current.Name = str.Trim ();
-                                                               current.Value = String.Empty;
+                                                       try {
+                                                               current = new Cookie ();
+                                                               int idx = str.IndexOf ('=');
+                                                               if (idx > 0) {
+                                                                       current.Name = str.Substring (0, idx).Trim ();
+                                                                       current.Value =  str.Substring (idx + 1).Trim ();
+                                                               } else {
+                                                                       current.Name = str.Trim ();
+                                                                       current.Value = String.Empty;
+                                                               }
+                                                               current.Version = version;
+                                                       } catch (CookieException) {
+                                                               current = null;
                                                        }
-                                                       current.Version = version;
                                                }
                                        }
                                        if (current != null) {
@@ -370,7 +372,7 @@ namespace System.Net {
                                                return false;
                                        if (InputStream.EndRead (ares) <= 0)
                                                return true;
-                               } catch (ObjectDisposedException e) {
+                               } catch (ObjectDisposedException) {
                                        input_stream = null;
                                        return true;
                                } catch {
@@ -404,7 +406,7 @@ namespace System.Net {
                }
 
                public long ContentLength64 {
-                       get { return content_length; }
+                       get { return is_chunked ? -1 : content_length; }
                }
 
                public string ContentType {
@@ -579,5 +581,4 @@ namespace System.Net {
                }
        }
 }
-#endif