Repository: eclipse-vertx/vert.x

Problem statement:
WebSocket request options not honored
```java
    HttpClient client = vertx.createHttpClient(new HttpClientOptions());

    RequestOptions options = new RequestOptions()
      .setHost("ws.cex.io")
      .setPort(443)
      .setSsl(true)
      .setURI("/ws");

    client.websocket(options, ws -> {
    });
```
Connection fails with because HTTP upgrade request is sent as clear text.


Hints:
This code works

```java
    HttpClient client = vertx.createHttpClient(new HttpClientOptions()
      .setDefaultHost("ws.cex.io")
      .setDefaultPort(443)
      .setSsl(true));

    client.websocket("/ws", ws -> {
    });
```

Patch:
diff --git a/src/main/java/io/vertx/core/http/impl/HttpClientImpl.java b/src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
--- a/src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
+++ b/src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
@@ -153,7 +153,7 @@ public HttpClientImpl(VertxInternal vertx, HttpClientOptions options) {
 
   @Override
   public HttpClient websocket(RequestOptions options, Handler<WebSocket> wsConnect) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), wsConnect);
+    return websocket(options, null, wsConnect);
   }
 
   @Override
@@ -164,7 +164,7 @@ public HttpClient websocket(int port, String host, String requestURI, Handler<We
 
   @Override
   public HttpClient websocket(RequestOptions options, Handler<WebSocket> wsConnect, Handler<Throwable> failureHandler) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), wsConnect, failureHandler);
+    return websocket(options, null, wsConnect, failureHandler);
   }
 
   public HttpClient websocket(int port, String host, String requestURI, Handler<WebSocket> wsConnect, Handler<Throwable> failureHandler){
@@ -184,7 +184,7 @@ public HttpClient websocket(String host, String requestURI, Handler<WebSocket> w
 
   @Override
   public HttpClient websocket(RequestOptions options, MultiMap headers, Handler<WebSocket> wsConnect) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), headers, wsConnect);
+    return websocket(options, headers, null, wsConnect);
   }
 
   @Override
@@ -195,7 +195,7 @@ public HttpClient websocket(int port, String host, String requestURI, MultiMap h
 
   @Override
   public HttpClient websocket(RequestOptions options, MultiMap headers, Handler<WebSocket> wsConnect, Handler<Throwable> failureHandler) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), headers, wsConnect, failureHandler);
+    return websocket(options, headers, null, wsConnect, failureHandler);
   }
 
   @Override
@@ -216,7 +216,7 @@ public HttpClient websocket(String host, String requestURI, MultiMap headers, Ha
 
   @Override
   public HttpClient websocket(RequestOptions options, MultiMap headers, WebsocketVersion version, Handler<WebSocket> wsConnect) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), headers, version, wsConnect);
+    return websocket(options, headers, version, null, wsConnect);
   }
 
   @Override
@@ -227,7 +227,7 @@ public HttpClient websocket(int port, String host, String requestURI, MultiMap h
 
   @Override
   public HttpClient websocket(RequestOptions options, MultiMap headers, WebsocketVersion version, Handler<WebSocket> wsConnect, Handler<Throwable> failureHandler) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), headers, version, wsConnect, failureHandler);
+    return websocket(options, headers, version, null, wsConnect, failureHandler);
   }
 
   @Override
@@ -250,7 +250,8 @@ public HttpClient websocket(String host, String requestURI, MultiMap headers, We
 
   @Override
   public HttpClient websocket(RequestOptions options, MultiMap headers, WebsocketVersion version, String subProtocols, Handler<WebSocket> wsConnect) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), headers, version, subProtocols, wsConnect);
+    websocketStream(options, headers, version, subProtocols).handler(wsConnect);
+    return this;
   }
 
   @Override
@@ -262,7 +263,8 @@ public HttpClient websocket(int port, String host, String requestURI, MultiMap h
 
   @Override
   public HttpClient websocket(RequestOptions options, MultiMap headers, WebsocketVersion version, String subProtocols, Handler<WebSocket> wsConnect, Handler<Throwable> failureHandler) {
-    return websocket(options.getPort(), options.getHost(), options.getURI(), headers, version, subProtocols, wsConnect, failureHandler);
+    websocketStream(options, headers, version, subProtocols).exceptionHandler(failureHandler).handler(wsConnect);
+    return this;
   }
 
   @Override


Test patch:
diff --git a/src/test/java/io/vertx/test/core/WebsocketTest.java b/src/test/java/io/vertx/test/core/WebsocketTest.java
--- a/src/test/java/io/vertx/test/core/WebsocketTest.java
+++ b/src/test/java/io/vertx/test/core/WebsocketTest.java
@@ -27,11 +27,25 @@
 import io.vertx.core.Vertx;
 import io.vertx.core.VertxOptions;
 import io.vertx.core.buffer.Buffer;
-import io.vertx.core.http.*;
+import io.vertx.core.http.ClientAuth;
+import io.vertx.core.http.HttpClient;
+import io.vertx.core.http.HttpClientOptions;
+import io.vertx.core.http.HttpMethod;
+import io.vertx.core.http.HttpServer;
+import io.vertx.core.http.HttpServerOptions;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.core.http.HttpVersion;
+import io.vertx.core.http.RequestOptions;
+import io.vertx.core.http.ServerWebSocket;
+import io.vertx.core.http.WebSocket;
+import io.vertx.core.http.WebSocketBase;
+import io.vertx.core.http.WebSocketFrame;
 import io.vertx.core.http.WebsocketRejectedException;
+import io.vertx.core.http.WebsocketVersion;
 import io.vertx.core.impl.ConcurrentHashSet;
 import io.vertx.core.net.NetServer;
 import io.vertx.core.net.NetSocket;
+import io.vertx.core.net.SelfSignedCertificate;
 import io.vertx.core.streams.ReadStream;
 import io.vertx.test.core.tls.Cert;
 import io.vertx.test.core.tls.Trust;
@@ -48,7 +62,12 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.*;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
@@ -1735,4 +1754,25 @@ private void doTestClientWebsocketConnectionCloseOnBadResponse(boolean keepAlive
       }
     }
   }
+
+  @Test
+  public void testClearClientSslOptions() {
+    SelfSignedCertificate certificate = SelfSignedCertificate.create();
+    HttpServerOptions serverOptions = new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT)
+      .setSsl(true)
+      .setKeyCertOptions(certificate.keyCertOptions());
+    HttpClientOptions options = new HttpClientOptions()
+      .setTrustAll(true)
+      .setVerifyHost(false);
+    client = vertx.createHttpClient(options);
+    server = vertx.createHttpServer(serverOptions).websocketHandler(WebSocketBase::close).listen(onSuccess(server -> {
+      RequestOptions requestOptions = new RequestOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setSsl(true);
+      client.websocket(requestOptions, ws -> {
+        ws.closeHandler(v -> {
+          testComplete();
+        });
+      });
+    }));
+    await();
+  }
 }