aspnet/AspNetWebStack

[HttpMessageContent] Invalid Server header when multiple values are present

manandre opened this issue · 1 comments

When serializing the Server header, the comma , separator is used while the RFC 9110 states that the space seaprator should be used, like for the User-Agent header.
It is also correctly stated and implemented in .NET runtime

How to reproduce the issue

using System.Net;

var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
httpResponseMessage.Headers.Add("Server", new[] {"My", "Gateway"});
var message = new HttpMessageContent(httpResponseMessage);
var messageString = await message.ReadAsStringAsync();
Console.WriteLine(messageString);

Obtained result

HTTP/1.1 200 OK
Server: My, Gateway

Expected result

HTTP/1.1 200 OK
Server: My Gateway

Fix proposal

Add the Server header to the existing list of _spaceSeparatedValueHeaderFields

// Set of header fields that should get serialized as space-separated values such as User-Agent.
private static readonly HashSet<string> _spaceSeparatedValueHeaderFields = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"User-Agent",
};

Thanks for contacting us.
We're not making any improvements in this area any more as this project is in maintenance mode. Only critical blocking issue with wide impact and security issues are considered.