IIS WebSockets handler (native C++) doesn't see the Upgrade header

73 Views Asked by At

I had this working on a previous computer, but I'm having difficulties getting my native C++ WebSockets module registered and running correctly under IIS 10 on my new Windows 11 Pro computer.

If I open a Telnet session to localhost 80 and send the following:

GET /test3.qws
Host: localhost
Upgrade: websocket
Connection: Upgrade
Origin: https://localhost
Sec-WebSocket-Key: Iv8io/9s+lYFgZWcXczP8Q==
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: test

That does cause IIS to run my module's OnExecuteRequestHandler() method. Unfortunately, when I query for the HttpHeaderUpgrade header, it comes back empty.

    USHORT cchUpgradeHeader = 0;
    pHttpContext->GetRequest()->GetHeader(HttpHeaderUpgrade, &cchUpgradeHeader);
    CheckIf(0 == cchUpgradeHeader, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED));

If I skip the zero length check and let it continue, it fails later when it tries to obtain the "websockets" named context.

    pHttpStoredContext = pHttpContext3->GetNamedContextContainer()->GetNamedContext(IIS_WEBSOCKET);
    CheckIf(NULL == pHttpStoredContext, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND));

So, it's definitely not being processed by IIS as a WebSockets request.

I've also tried connecting to the same resource using JavaScript from Firefox and Edge, but in those tests my module isn't called. Instead, IIS simply responds with:

HTTP/1.1 200 OK
Server: Microsoft-IIS/10.0
Date: Fri, 28 Apr 2023 21:09:02 GMT
Content-Length: 0

I have Visual Studio attached to w3wp.exe, so I am watching what happens, but when tested from the web browser, my code isn't called at all.

My module is 32-bit, and it must be mostly registered correctly since it is called from the Telnet test.

        <handlers accessPolicy="Read, Script">
            <add name="ASPClassic" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="File" />
            <add name="QuadooWebSocket" path="*.qws" verb="*" modules="WebSocketModule32" scriptProcessor="X:\path\ActiveQuadoo.dll" resourceType="File" preCondition="bitness32" />
            ...

Earlier in this testing, IIS was complaining about my qws file type missing a MIME definition. I couldn't remember what I used previously, so I registered it as text/plain.

Any idea why IIS isn't returning the Upgrade header?

Thanks!

0

There are 0 best solutions below