Skip to content

Commit 8462ca4

Browse files
mkoubagsmet
authored andcommitted
WebSockets Next - client: use 443 if port is undefined and https is set
(cherry picked from commit 5e4e3ba)
1 parent dc5e281 commit 8462ca4

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/BasicWebSocketConnectorImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ public Uni<WebSocketClientConnection> connect() {
117117
// TODO would it make sense to share clients?
118118
WebSocketClient client = vertx.createWebSocketClient(populateClientOptions());
119119

120-
WebSocketConnectOptions connectOptions = new WebSocketConnectOptions()
121-
.setSsl(baseUri.getScheme().equals("https"))
122-
.setHost(baseUri.getHost())
123-
.setPort(baseUri.getPort());
120+
WebSocketConnectOptions connectOptions = newConnectOptions(baseUri);
124121
StringBuilder requestUri = new StringBuilder();
125122
String mergedPath = mergePath(baseUri.getPath(), replacePathParameters(path));
126123
requestUri.append(mergedPath);

extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorBase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.vertx.core.Vertx;
2222
import io.vertx.core.buffer.Buffer;
2323
import io.vertx.core.http.WebSocketClientOptions;
24+
import io.vertx.core.http.WebSocketConnectOptions;
2425
import io.vertx.core.net.SSLOptions;
2526

2627
abstract class WebSocketConnectorBase<THIS extends WebSocketConnectorBase<THIS>> {
@@ -191,4 +192,21 @@ protected WebSocketClientOptions populateClientOptions() {
191192
}
192193
return clientOptions;
193194
}
195+
196+
protected WebSocketConnectOptions newConnectOptions(URI serverEndpointUri) {
197+
WebSocketConnectOptions connectOptions = new WebSocketConnectOptions()
198+
.setSsl(isHttps(serverEndpointUri))
199+
.setHost(serverEndpointUri.getHost());
200+
if (serverEndpointUri.getPort() != -1) {
201+
connectOptions.setPort(serverEndpointUri.getPort());
202+
} else if (isHttps(serverEndpointUri)) {
203+
// If port is undefined and https is used then use 443 by default
204+
connectOptions.setPort(443);
205+
}
206+
return connectOptions;
207+
}
208+
209+
protected boolean isHttps(URI uri) {
210+
return "https".equals(uri.getScheme());
211+
}
194212
}

extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ public Uni<WebSocketClientConnection> connect() {
7373
throw new WebSocketClientException(e);
7474
}
7575

76-
WebSocketConnectOptions connectOptions = new WebSocketConnectOptions()
77-
.setSsl(serverEndpointUri.getScheme().equals("https"))
78-
.setHost(serverEndpointUri.getHost())
79-
.setPort(serverEndpointUri.getPort());
76+
WebSocketConnectOptions connectOptions = newConnectOptions(serverEndpointUri);
8077
StringBuilder uri = new StringBuilder();
8178
if (serverEndpointUri.getPath() != null) {
8279
uri.append(serverEndpointUri.getRawPath());

0 commit comments

Comments
 (0)