I have a .Net Core application that uses System.Net.Http.HttpClient to send a request to a .Net Core service.
I send multiple values for a single header.
var message = new HttpRequestMessage();
message.Headers.Add("Header1", "value1");
message.Headers.Add("Header1", "value2");
await client.SendAsync(message);
At this point if I inspect message.Headers, I see that "Header1" is being tracked as two distinct strings.
However, in the middleware of my receiveing .Net Core service, the values of "Header1" are joined.
public async Task Invoke(HttpContext httpContext)
{
var header1 = httpContext.Request.Headers["Header1"];
}
The header1 variable here is of StringValues type, but it is an array of 1 string, instead of the expected 2. The value of this single string is "value1, value2".
I have no way to distinguish between whether "value1, value2" was two headers that were joined together or if it was originally a single value that happened to be equal to this, therefore, I cannot effectively parse the header value properly.
Does anyone else see this behavior? I would expect the header1 StringValues to be an array with two elements that I can easily parse, not a single string.