using System.Net.Http.Headers;
public static void Main()
ParseAndPrint("null", null);
ParseAndPrint("empty", "");
ParseAndPrint("whitespace", " ");
ParseAndPrint("invalid", "max-age=-1");
ParseAndPrint("simple", "max-age=60");
ParseAndPrint("comma-separated", "max-age=60,no-cache");
ParseAndPrint("comma-whitespace-separated", "max-age=60, no-store");
ParseAndPrint("comma-weird-whitespace-separated", "max-age=60,no-cache , no-cache,\tno-store");
public static void ParseAndPrint(string name, string cchvstr)
CacheControlHeaderValue cchv;
Console.WriteLine(name+":");
if (!CacheControlHeaderValue.TryParse(cchvstr, out cchv))
Console.WriteLine("\tNot parsed!");
Console.WriteLine("\tnull!");
Console.WriteLine("\tmax-age: "+cchv.MaxAge);
Console.WriteLine("\tno-cache: "+cchv.NoCache);
Console.WriteLine("\tno-store: "+cchv.NoStore);