When establishing websocket connection, firefox sends such Connection header: Connection: keep-alive, Upgrade and System.Net.HttpListener can't recognize the Upgrade
It can be tested with inserting this test case
[InlineData("Connection: keep-alive, Upgrade\r\nUpgrade: websocket", true)]
to the IsWebSocketRequest_GetProperty_ReturnsExpected test of HttpListenerRequestTests.cs
Which OS? Windows? Linux? Both?
Both
I ran into this issue today.
The spec says that the Connection header need only _include_ the token "Upgrade", but the HttpListenerRequest checks for string equality.
Here's a workaround:
/// <summary>
/// Workaround https://github.com/dotnet/corefx/issues/24550.
/// </summary>
private static void WorkaroundFixHeaders(HttpListenerRequest request)
{
if (string.IsNullOrEmpty(request.Headers["Connection"]))
{
return;
}
// There are more token seperators possible (see RFC 2616 Section 2.2) but these are a reasonable subset.
Regex splitter = new Regex(@"(\s|[,;])+");
// This copies the values to a new array.
string[] connectionValues = request.Headers.GetValues("Connection");
// Removes the header.
request.Headers.Remove("Connection");
var allTokens = from connection in connectionValues
from token in splitter.Split(connection)
select token;
// Adds each individual token back.
allTokens.ToList().ForEach(value => request.Headers.Add("Connection", value));
}
Not able to repro, probably has already been fixed here.
Please re-open this bug if the problem still exists.
Most helpful comment
I ran into this issue today.
The spec says that the Connection header need only _include_ the token "Upgrade", but the HttpListenerRequest checks for string equality.
Here's a workaround: