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 upgrade request missing the Connection header #8189

Closed
4e6 opened this issue Jan 3, 2024 · 2 comments
Closed

WebSocket upgrade request missing the Connection header #8189

4e6 opened this issue Jan 3, 2024 · 2 comments
Assignees
Labels
4.x Version 4.x P2 websocket WebSocket in Helidon

Comments

@4e6
Copy link

4e6 commented Jan 3, 2024

Environment Details

  • Helidon Version: 4.0.2
  • Helidon SE
  • JDK version: openjdk 21.0.1
  • OS: Archlinux
  • Docker version (if applicable): -

Problem Description

When trying to create a WebSocket connection with WsClient, it fails to upgrade the connection

Exception in thread "main" io.helidon.webclient.websocket.WsClientException: Failed to upgrade to WebSocket. Response: 200 OK: Via: 1.1 fly.io
Content-Length: 630
Content-Type: text/plain
Date: Wed, 03 Jan 2024 19:57:01 GMT
Server: Fly/ec8196c09 (2024-01-02)
fly-request-id: 01HK8ED5H2PDAM0NC27TD3ZGQD-lhr

	at [email protected]/io.helicon.webclient.websocket.WsClientImpl.connect(WsClientImpl.java:123)

According to the Mozilla doc, a WebSocket upgrade request should contain two headers:

Connection: Upgrade
Upgrade: websocket

Debugging showed that the upgrade request sets the Upgrade header but is missing the Connection one

public UpgradeResponse upgrade(String protocol) {
if (!headers().contains(HeaderNames.UPGRADE)) {
headers().set(HeaderNames.UPGRADE, protocol);
}

After setting the Connection header (see the example below), the connection was successfully established.

Steps to reproduce

This example results in an io.helidon.webclient.websocket.WsClientException: Failed to upgrade to WebSocket.

io.helidon.webclient.websocket.WsClient.builder()
    .build()
    .connect(
        new java.net.URI("wss://echo.websocket.org/"), 
        new io.helidon.websocket.WsListener() {}
    );

After adding a Connection header, the connection is established successfully

var headersMap = new java.util.HashMap<String, String>();
headersMap.put("CONNECTION", "Upgrade");
io.helidon.webclient.websocket.WsClient.builder()
    .defaultHeadersMap(headersMap)
    .build()
    .connect(
        new java.net.URI("wss://echo.websocket.org/"), 
        new io.helidon.websocket.WsListener() {}
    );
@m0mus m0mus added P2 4.x Version 4.x websocket WebSocket in Helidon labels Jan 4, 2024
@spericas
Copy link
Member

spericas commented Jan 5, 2024

@4e6 Thanks for the report, yes it looks like that header is missing. Just to fully understand your scenario, you are using Helidon as a client of some third-party WS server right?

@4e6
Copy link
Author

4e6 commented Jan 5, 2024

Yes, I would like to establish a connection with the Yjs server yjs/y-websocket.

@spericas spericas closed this as completed Jan 8, 2024
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x P2 websocket WebSocket in Helidon
Projects
Archived in project
Development

No branches or pull requests

3 participants