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

Websocket handshake fails using a http proxy #518

Open
ht-sp opened this issue Sep 11, 2024 · 1 comment
Open

Websocket handshake fails using a http proxy #518

ht-sp opened this issue Sep 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ht-sp
Copy link

ht-sp commented Sep 11, 2024

First of all, thank you for your great work, the current version works very stable for me.

If i use a http proxy, the connection fails:

URI proxyUri = new URI("http", null, proxy.host, proxy.port, null, null, null);
WebOptionsBuilder webOptionsBuilder = Whatsapp.webBuilder()
                        .newConnection(UUID.fromString(session.uuid()))
                        .name(session.name())
                        .proxy(proxyUri)
                        .historyLength(WebHistoryLength.extended());

Presumably this is because the websocket handshake payload contains the wrong Host:
In WebSocketClient:

private CompletableFuture<Void> handshake(String path) {
    var payload = generateWebSocketUpgradePayload(path);
    return underlyingSocket.writeAsync(ByteBuffer.wrap(payload.getBytes()))
            .thenComposeAsync(writeResult -> readWebSocketUpgradeResponse())
            .thenComposeAsync(this::parseWebSocketUpgradeResponse);
}

The payload is:

GET /ws/chat HTTP/1.1
Host: proxy.host:1234
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: DludGb/DusK1iE8OHJVNHw==


If i fix up the handshake payload during debugging:

payload = payload.replace("proxy.host:1234", "web.whatsapp.com")

The connection works as expected.

@Auties00 Auties00 added the bug Something isn't working label Sep 14, 2024
@Auties00
Copy link
Owner

Thanks for reporting, will be fixed in 0.0.8, eta next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants