Skip to content

Commit

Permalink
WebSockets Next - client: use 443 if port is undefined and https is set
Browse files Browse the repository at this point in the history
(cherry picked from commit 5e4e3ba)
  • Loading branch information
mkouba authored and gsmet committed Jul 9, 2024
1 parent dc5e281 commit 8462ca4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ public Uni<WebSocketClientConnection> connect() {
// TODO would it make sense to share clients?
WebSocketClient client = vertx.createWebSocketClient(populateClientOptions());

WebSocketConnectOptions connectOptions = new WebSocketConnectOptions()
.setSsl(baseUri.getScheme().equals("https"))
.setHost(baseUri.getHost())
.setPort(baseUri.getPort());
WebSocketConnectOptions connectOptions = newConnectOptions(baseUri);
StringBuilder requestUri = new StringBuilder();
String mergedPath = mergePath(baseUri.getPath(), replacePathParameters(path));
requestUri.append(mergedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.WebSocketClientOptions;
import io.vertx.core.http.WebSocketConnectOptions;
import io.vertx.core.net.SSLOptions;

abstract class WebSocketConnectorBase<THIS extends WebSocketConnectorBase<THIS>> {
Expand Down Expand Up @@ -191,4 +192,21 @@ protected WebSocketClientOptions populateClientOptions() {
}
return clientOptions;
}

protected WebSocketConnectOptions newConnectOptions(URI serverEndpointUri) {
WebSocketConnectOptions connectOptions = new WebSocketConnectOptions()
.setSsl(isHttps(serverEndpointUri))
.setHost(serverEndpointUri.getHost());
if (serverEndpointUri.getPort() != -1) {
connectOptions.setPort(serverEndpointUri.getPort());
} else if (isHttps(serverEndpointUri)) {
// If port is undefined and https is used then use 443 by default
connectOptions.setPort(443);
}
return connectOptions;
}

protected boolean isHttps(URI uri) {
return "https".equals(uri.getScheme());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public Uni<WebSocketClientConnection> connect() {
throw new WebSocketClientException(e);
}

WebSocketConnectOptions connectOptions = new WebSocketConnectOptions()
.setSsl(serverEndpointUri.getScheme().equals("https"))
.setHost(serverEndpointUri.getHost())
.setPort(serverEndpointUri.getPort());
WebSocketConnectOptions connectOptions = newConnectOptions(serverEndpointUri);
StringBuilder uri = new StringBuilder();
if (serverEndpointUri.getPath() != null) {
uri.append(serverEndpointUri.getRawPath());
Expand Down

0 comments on commit 8462ca4

Please sign in to comment.