So I my app chanced authentication Management, previously all headers were added in a load balancer. The new method works and in order to not have to rewrite code we are using an angular interceptor to inject the headers in the HTTP request there
HttpContext.Current.Response.AddHeader("ICAM_RIOT", "RIOT");
private void hasResponseHeaderCollection(string headerName, string Value)
{
if (!HttpContext.Current.Response.Headers.AllKeys.Any(k => string.Equals(k, headerName)))
{
HttpContext.Current.Response.AddHeader(headerName, Value);
}
}
private string GetHeaderStringValue(string headerName)
{
return HttpContext.Current.Request.Headers[headerName] ?? "";
}
Please see the photos,
All the headers are UPPER CASE
WHEN received on the .Net api side they are camel Case
For instance ICAM_MAIL becomes Icam_mail
I even tried on the .net side to add a rseponse header all caps and it comes back camel case as well
CodePudding user response:
HTTP headers are case insensitive. Whenever you lookup a header value by Key it needs to be a case insensitive match.
Request.Headers[headerName] handles this for you, but Response.Headers.AllKeys.Any(...) will not because you're doing your own string comparison, which defaults to case sensitive matching. Use the overload of string.Equals that allows for a StringComparison object and use StringComparer.InvariantCultureIgnoreCase.
