HTTP header constants

Topics: ASP.NET Web API, General
May 12, 2012 at 12:15 PM

I am coding something and struggling to find constants for HTTP request and response headers in System.Net.Http.dll (for example "If-Match", "If-None-Match").

I looked at the code using Reflector (that part is not open source) and I see strings and cannot find constants.

Do we have constants and I cannot find them? Or was it a deliberate decision not to use constants for names? 

 

May 12, 2012 at 5:36 PM
Both are available as request.Headers.IfMatch and request.Headers.IfNoneMatch.
May 12, 2012 at 6:16 PM

Thanks Brad. But request.Headers.IfMatch and request.Headers.IfNoneMatch are objects.

What I need is a constant string defined as for all common HTTP headers. I am writing unit tests and need to construct HttpRequestMessage and add headers and wondering of there is a class containing constants of these common header strings. 

May 12, 2012 at 7:02 PM

There is no publicly exposed table of header names exposed in System.Net.

Hope this helps,

Henrik

May 12, 2012 at 7:07 PM

Thanks a lot. I will define my own constants.