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

The 'Connection' header value 'Upgrade, Upgrade' is invalid. #315

Closed
asharmaarcadix opened this issue Mar 24, 2023 · 1 comment
Closed

Comments

@asharmaarcadix
Copy link

Hi,

We are having a node.js Server for socket.io and have hosted it to IIS server.

And for client side we are using SocketIOClient package in .net core 6.0.
as we try to start a connection we face an issue
"TransportException: Could not connect to 'ws://localhost:8000/socket.io/?EIO=4&transport=websocket'"
"The 'Connection' header value 'Upgrade, Upgrade' is invalid."

image

image

But when we try to make connection without hosting it to IIS server ( normally in local). It is working fine but after hosting it to IIS Server, we are not able to make connection.

Here is the image from index.js of server side.
image

Can you please guide me to resolve this issue.

@doghappy
Copy link
Owner

doghappy commented Mar 31, 2023

thanks for your feedback.

it seems that IIS returned 2 Connection: Upgrade

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 don't know why there are 2 Connection: Upgrade. the implementation 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));
        }

I haven't found root cause yet. so let's use HttpPooling instead of WebSocket

var io = new SocketIO(SocketIOOptions
{
    AutoUpgrade = false,
});

@doghappy doghappy changed the title Not able to make Connection to Server. Not able to make Connection to IIS Server. Mar 31, 2023
@doghappy doghappy changed the title Not able to make Connection to IIS Server. The 'Connection' header value 'Upgrade, Upgrade' is invalid. Mar 31, 2023
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

2 participants