Skip to content

PR #12659 - allow HttpVersion to be set on WebSocket ClientUpgradeRequest #13185

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

Open
wants to merge 2 commits into
base: jetty-12.1.x
Choose a base branch
from

Conversation

lachlan-roberts
Copy link
Contributor

closes #12659

Implement setHttpVersion method on ClientUpgradeRequest so that WebSocketClients supporting both HTTP/1.1 and HTTP/2 websocket upgrades can select which one to use.

@lachlan-roberts lachlan-roberts requested a review from sbordet May 28, 2025 22:10
@lachlan-roberts lachlan-roberts self-assigned this May 28, 2025
@lachlan-roberts lachlan-roberts moved this to 👀 In review in Jetty 12.1.0 May 28, 2025
/**
* Set the HTTP Version to use for the websocket upgrade.
* <p>
* Currently only HTTP/1.1 (with RFC6455) and HTTP/2 (with RFC8441) are supported.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid specifying this, as when we implement it for HTTP/3 we will forget about this javadoc.

String scheme = uri.getScheme();
if (!HttpScheme.WS.is(scheme) && !HttpScheme.WSS.is(scheme))
throw new IllegalArgumentException("URI scheme must be 'ws' or 'wss'");
this.host = this.requestURI.getHost();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal feels wrong, as WebSocketClient.connect(endPoint, URI, ClientUpgradeRequest) should have been deprecated instead.

I would have kept WebSocketClient.connect(endPoint, URI), but when I pass ClientUpgradeRequest, then everything is configured in it, rather than the URI separated from ClientUpgradeRequest, so just have
WebSocketClient.connect(endPoint, ClientUpgradeRequest).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this constructor had been deprecated for ages so I removed it.

Otherwise it is not really related to this PR, so reverting.

Copy link
Contributor Author

@lachlan-roberts lachlan-roberts Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened issue #13213 for this

public String getHttpVersion()
{
throw new UnsupportedOperationException("HttpVersion not available on ClientUpgradeRequest");
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now very weird that we cannot get the URI host (and other things) from a request.

assertThat(wsEndPoint.closeReason, equalTo("normal close from test"));

// Wait for the request to complete on server before stopping.
assertTrue(latch.await(5, TimeUnit.SECONDS));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not sure that the upgrade actually happened with HTTP/2.

Can you modify TestJettyWebSocketServlet to have a /ws/version endpoint that returns the HTTP version as seen by the server, and then you assert that in the test?

Signed-off-by: Lachlan Roberts <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

2 participants