[system.net.http] Accept header with multiple values. Fixes #27352
[mono.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / HttpRequestHeaders.cs
index 95f1cf9ee79e8b498304c8309e61d2f85e1f0192..4f6ceeef8e96102c57d94a4f3714ec3ea9fd6b3c 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Net.Http.Headers
 {
        public sealed class HttpRequestHeaders : HttpHeaders
        {
-               bool? expectContinue, connectionclose, transferEncodingChunked;
+               bool? expectContinue;
 
                internal HttpRequestHeaders ()
                        : base (HttpHeaderKind.Request)
@@ -89,7 +89,7 @@ namespace System.Net.Http.Headers
 
                public bool? ConnectionClose {
                        get {
-                               if (connectionclose == true || Connection.Contains ("close"))
+                               if (connectionclose == true || Connection.Find (l => string.Equals (l, "close", StringComparison.OrdinalIgnoreCase)) != null)
                                        return true;
 
                                return connectionclose;
@@ -106,12 +106,18 @@ namespace System.Net.Http.Headers
                        }
                }
 
+               internal bool ConnectionKeepAlive {
+                       get {
+                               return Connection.Find (l => string.Equals (l, "Keep-Alive", StringComparison.OrdinalIgnoreCase)) != null;
+                       }
+               }
+
                public DateTimeOffset? Date {
                        get {
                                return GetValue<DateTimeOffset?> ("Date");
                        }
                        set {
-                               AddOrRemove ("Date", value);
+                               AddOrRemove ("Date", value, Parser.DateTime.ToString);
                        }
                }
 
@@ -126,7 +132,7 @@ namespace System.Net.Http.Headers
                                if (expectContinue.HasValue)
                                        return expectContinue;
 
-                               var found = TransferEncoding.Find (l => StringComparer.OrdinalIgnoreCase.Equals (l.Value, "100-continue"));
+                               var found = TransferEncoding.Find (l => string.Equals (l.Value, "100-continue", StringComparison.OrdinalIgnoreCase));
                                return found != null ? true : (bool?) null;
                        }
                        set {
@@ -147,6 +153,9 @@ namespace System.Net.Http.Headers
                                return GetValue<string> ("From");
                        }
                        set {
+                               if (!string.IsNullOrEmpty (value) && !Parser.EmailAddress.TryParse (value, out value))
+                                       throw new FormatException ();
+
                                AddOrRemove ("From", value);
                        }
                }
@@ -171,7 +180,7 @@ namespace System.Net.Http.Headers
                                return GetValue<DateTimeOffset?> ("If-Modified-Since");
                        }
                        set {
-                               AddOrRemove ("If-Modified-Since", value);
+                               AddOrRemove ("If-Modified-Since", value, Parser.DateTime.ToString);
                        }
                }
 
@@ -182,8 +191,7 @@ namespace System.Net.Http.Headers
                }
 
                public RangeConditionHeaderValue IfRange {
-                       get
-                       {
+                       get {
                                return GetValue<RangeConditionHeaderValue> ("If-Range");
                        }
                        set {
@@ -196,7 +204,7 @@ namespace System.Net.Http.Headers
                                return GetValue<DateTimeOffset?> ("If-Unmodified-Since");
                        }
                        set {
-                               AddOrRemove ("If-Unmodified-Since", value);
+                               AddOrRemove ("If-Unmodified-Since", value, Parser.DateTime.ToString);
                        }
                }
 
@@ -265,7 +273,7 @@ namespace System.Net.Http.Headers
                                if (transferEncodingChunked.HasValue)
                                        return transferEncodingChunked;
 
-                               var found = TransferEncoding.Find (l => StringComparer.OrdinalIgnoreCase.Equals (l.Value, "chunked"));
+                               var found = TransferEncoding.Find (l => string.Equals (l.Value, "chunked", StringComparison.OrdinalIgnoreCase));
                                return found != null ? true : (bool?) null;
                        }
                        set {
@@ -303,5 +311,12 @@ namespace System.Net.Http.Headers
                                return GetValues<WarningHeaderValue> ("Warning");
                        }
                }
+
+               internal void AddHeaders (HttpRequestHeaders headers)
+               {
+                       foreach (var header in headers) {
+                               TryAddWithoutValidation (header.Key, header.Value);
+                       }
+               }
        }
 }