poco proxy: websocket connection closes: Unauthorized

45 Views Asked by At

I'm trying to proxy HTTP (I'm not dealing with any HTTPS here) Websocket connections between a client and vscode-server, but the websocket requests are always "interrupted while the page was loading". I went ahead and spun up the example poco websockets server, and it talked absolutely fine through my proxy, so vscode-server must be doing something that I've not yet considered, which is not very unlikely since I have zero prior experience in websockets.

What my code is supposed to do is this:

  1. Open a websocket which the client can connect to. Open a websocket between the proxy and the server.
  2. Redirect data from the client to the server by replaying the data, and vice-versa

The browser tells me that the handshake failed because of 401 unauthorized.

Here's the snippet that handles the requests:

    do {
        svlen = svsocket.receiveFrame(svbuffer, sizeof(svbuffer), svflags);
        Application::instance().logger().information(
            Poco::format("client -> server (length=%d, flags=0x%x).", svlen, unsigned(svflags)));
        clsocket.sendFrame(svbuffer, svlen, svflags);

        if (!(svlen > 0 && (svflags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)) {
            break;
        }

        cllen = clsocket.receiveFrame(clbuffer, sizeof(clbuffer), clflags);
        Application::instance().logger().information(
            Poco::format("server -> client (length=%d, flags=0x%x).", cllen, unsigned(clflags)));
        svsocket.sendFrame(clbuffer, cllen, clflags);
    } while (cllen > 0 && (clflags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);

(I seemingly cannot make this pretty messy piece of code any prettier, sorry)

Do you reckon there is something that can be set before communication starts which I'm currently missing? Is my approach fundamentally flawed?

I was expecting it to not close the connection and error out on the client. I'm not sure how to proceed from this point so I haven't tried much more than what I provided above.

0

There are 0 best solutions below