Has Microsoft created a class full of constants for the standard HTTP header names or will I have to write my own?
using System.Net.HttpRequestHeader;
using System.Net.HttpResponseHeader;
public class Example {
static void Main() {
Console.WriteLine(HttpRequestHeader.IfModifiedSince.ToHeaderString());
// If-Modified-Since
Console.WriteLine(HttpResponseHeader.ContentLength.ToHeaderString());
// Content-Length
}
}
static class ExtensionMethods {
public static string ToHeaderString(this HttpRequestHeader instance)
{
return Regex.Replace(instance.ToString(), "(\\B[A-Z])", "-$1");
}
public static string ToHeaderString(this HttpResponseHeader instance)
{
return Regex.Replace(instance.ToString(), "(\\B[A-Z])", "-$1");
}
}