Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate http header: Connection #699

Open
doghappy opened this issue Apr 1, 2023 · 0 comments
Open

Duplicate http header: Connection #699

doghappy opened this issue Apr 1, 2023 · 0 comments

Comments

@doghappy
Copy link

doghappy commented Apr 1, 2023

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="&quot;%programfiles%\nodejs\node.exe&quot;" />

        <webSocket enabled="true" receiveBufferLimit="4194304" pingInterval="00:00:10"/>
    </system.webServer>
</configuration>

Env:

  • iisnode: v0.2.21
  • socket.io: v4
  • IIS: v10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant