Merge pull request #463 from strawd/concurrent-requests
[mono.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / Parser.cs
index 85b520dbb69f083f674a7c208562b60bdefb49d3..8489ae9bf724447a9fbb163afe9563ec281b64c2 100644 (file)
@@ -28,6 +28,7 @@
 
 using System.Net.Mail;
 using System.Globalization;
+using System.Collections.Generic;
 
 namespace System.Net.Http.Headers
 {
@@ -59,6 +60,14 @@ namespace System.Net.Http.Headers
                                }
                        }
 
+                       public static bool TryCheck (string s)
+                       {
+                               if (s == null)
+                                       return false;
+
+                               return Lexer.IsValidToken (s);
+                       }
+
                        public static void CheckQuotedString (string s)
                        {
                                if (s == null)
@@ -93,6 +102,8 @@ namespace System.Net.Http.Headers
 
                public static class DateTime
                {
+                       public new static readonly Func<object, string> ToString = l => ((DateTimeOffset) l).ToString ("r", CultureInfo.InvariantCulture);
+                       
                        public static bool TryParse (string input, out DateTimeOffset result)
                        {
                                return Lexer.TryGetDateValue (input, out result);
@@ -114,6 +125,17 @@ namespace System.Net.Http.Headers
                        }
                }
 
+               public static class Host
+               {
+                       public static bool TryParse (string input, out string result)
+                       {
+                               result = input;
+
+                               System.Uri dummy;
+                               return System.Uri.TryCreate ("http://u@" + input + "/", UriKind.Absolute, out dummy);
+                       }
+               }
+
                public static class Int
                {
                        public static bool TryParse (string input, out int result)
@@ -122,6 +144,30 @@ namespace System.Net.Http.Headers
                        }
                }
 
+               public static class Long
+               {
+                       public static bool TryParse (string input, out long result)
+                       {
+                               return long.TryParse (input, NumberStyles.None, CultureInfo.InvariantCulture, out result);
+                       }
+               }
+
+               public static class MD5
+               {
+                       public new static readonly Func<object, string> ToString = l => Convert.ToBase64String ((byte[]) l);
+
+                       public static bool TryParse (string input, out byte[] result)
+                       {
+                               try {
+                                       result = Convert.FromBase64String (input);
+                                       return true;
+                               } catch {
+                                       result = null;
+                                       return false;
+                               }
+                       }
+               }
+
                public static class TimeSpanSeconds
                {
                        public static bool TryParse (string input, out TimeSpan result)
@@ -141,7 +187,7 @@ namespace System.Net.Http.Headers
                {
                        public static bool TryParse (string input, out System.Uri result)
                        {
-                               return System.Uri.TryCreate ("http://" + input + "/", UriKind.Absolute, out result);
+                               return System.Uri.TryCreate (input, UriKind.RelativeOrAbsolute, out result);
                        }
 
                        public static void Check (string s)