I have a nodejs service which hosted on IIS, I got duplicate http header Connection when websocket handshake
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Server: Microsoft-IIS/10.0
Connection: Upgrade
Sec-WebSocket-Accept: NFMfylbwIygrHXmqMg4BFjGQITw=
Connection: Upgrade
X-Powered-By: ASP.NET
Date: Fri, 31 Mar 2023 14:58:21 GMT
EndTime: 22:58:21.838
ReceivedBytes: 109
SentBytes: 0
I also have a .NET client, it will connect to that service by websocket. but the implementation of ClientWebSocket of Microsoft will throw an exception after received that response:
ValidateHeader(response.Headers, HttpKnownHeaderNames.Connection, "Upgrade");
private static void ValidateHeader(HttpHeaders headers, string name, string expectedValue)
{
if (headers.NonValidated.TryGetValues(name, out HeaderStringValues hsv))
{
if (hsv.Count == 1)
{
foreach (string value in hsv)
{
if (string.Equals(value, expectedValue, StringComparison.OrdinalIgnoreCase))
{
return;
}
break;
}
}
throw new WebSocketException(WebSocketError.HeaderError, SR.Format(SR.net_WebSockets_InvalidResponseHeader, name, hsv));
}
throw new WebSocketException(WebSocketError.Faulted, SR.Format(SR.net_WebSockets_MissingResponseHeader, name));
}
The source code for the above can be found here: https://source.dot.net/#System.Net.WebSockets.Client/System/Net/WebSockets/WebSocketHandle.Managed.cs,9d3cf4c1f519f3a3,references
The expected Connection: Upgrade should be only one. Is this caused by iisnode?
web.config
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="v4-ws.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="v4-ws.js"/>
</rule>
<rule name="SocketIO" patternSyntax="ECMAScript">
<match url="socket.io.+"/>
<action type="Rewrite" url="v4-ws.js"/>
</rule>
</rules>
</rewrite>
<iisnode nodeProcessCommandLine=""%programfiles%\nodejs\node.exe"" />
<webSocket enabled="true" receiveBufferLimit="4194304" pingInterval="00:00:10"/>
</system.webServer>
</configuration>
Env:
- iisnode: v0.2.21
- socket.io: v4
- IIS: v10
I have a nodejs service which hosted on IIS, I got duplicate http header
Connectionwhen websocket handshakeI also have a .NET client, it will connect to that service by websocket. but the implementation of ClientWebSocket of Microsoft will throw an exception after received that response:
The source code for the above can be found here: https://source.dot.net/#System.Net.WebSockets.Client/System/Net/WebSockets/WebSocketHandle.Managed.cs,9d3cf4c1f519f3a3,references
The expected
Connection: Upgradeshould be only one. Is this caused by iisnode?web.config
Env: