Skip to content

Commit 5b2d601

Browse files
committed
Remove HttpServerConfig#ssl boolean
Motivation: HttpServerConfig has copied the boolean ssl flag from HttpServerOptions. Since on HTTP server there is no start TLS behavior, we can remove this configuration and state that ssl <=> ssl options != null Changes: Remove HttpServerConfig#ssl boolean and update tests / examples accordingly.
1 parent eddee86 commit 5b2d601

File tree

12 files changed

+91
-102
lines changed

12 files changed

+91
-102
lines changed

vertx-core/src/main/asciidoc/http.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Vert.x HTTP servers can be configured to use HTTPS in exactly the same way as TC
5151
{@link examples.HttpExamples#configurationOfAnHttpsServer}
5252
----
5353

54+
NOTE: there is no ssl setting on `HttpServerConfig` like there used to be on `HttpServerOptions`, providing ssl options when creating a server indicates the server uses TLS.
55+
5456
You can read more about <<server_ssl,SSL server configuration>>
5557

5658
=== Configuring an HTTP/1.x server

vertx-core/src/main/java/examples/HttpExamples.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,17 @@ public void configurationOfAnHttpsServer(Vertx vertx) {
100100
setPassword("password-of-your-keystore")
101101
);
102102

103-
HttpServerConfig config = new HttpServerConfig()
104-
.setSsl(true);
105-
106-
HttpServer server = vertx.createHttpServer(config, sslOptions);
103+
HttpServer server = vertx.createHttpServer(sslOptions);
107104
}
108105

109106
public void configurationOfAnHttp1Server(Vertx vertx) {
110107
HttpServerConfig config = new HttpServerConfig()
111-
.setSsl(true)
112108
.setHttp1Config(new Http1ServerConfig()
113109
.setMaxInitialLineLength(1024));
114110
}
115111

116112
public void configurationOfAnH2Server(Vertx vertx) {
117113
HttpServerConfig config = new HttpServerConfig()
118-
.setSsl(true)
119114
.setHttp2Config(new Http2ServerConfig()
120115
.setInitialSettings(new Http2Settings()
121116
.setMaxConcurrentStreams(250)));
@@ -137,8 +132,7 @@ public void configurationOfH3ServerConcurrency(Vertx vertx) {
137132

138133
public void configurationOfAHybridServer(Vertx vertx) {
139134
HttpServerConfig config = new HttpServerConfig()
140-
.setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_2, HttpVersion.HTTP_3)
141-
.setSsl(true);
135+
.setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_2, HttpVersion.HTTP_3);
142136

143137
ServerSSLOptions sslOptions = new ServerSSLOptions()
144138
.setKeyCertOptions(new JksOptions().setPath("/path/to/my/keystore"));

vertx-core/src/main/java/examples/SslExamples.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,22 +314,18 @@ public void exampleSSLEngine(Vertx vertx, JksOptions keyStoreOptions) {
314314

315315
ServerSSLOptions sslOptions = new ServerSSLOptions()
316316
.setKeyCertOptions(keyStoreOptions);
317-
HttpServerConfig config = new HttpServerConfig()
318-
.setSsl(true);
319317

320318
// Use JDK SSL engine
321-
HttpServer server = vertx.createHttpServer(config);
319+
HttpServer server = vertx.createHttpServer(sslOptions);
322320

323321
// Use JDK SSL engine explicitly
324322
server = vertx.httpServerBuilder()
325-
.with(config)
326323
.with(sslOptions)
327324
.with(new JdkSSLEngineOptions())
328325
.build();
329326

330327
// Use OpenSSL engine
331328
server = vertx.httpServerBuilder()
332-
.with(config)
333329
.with(sslOptions)
334330
.with(new OpenSSLEngineOptions())
335331
.build();

vertx-core/src/main/java/io/vertx/core/Vertx.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,22 @@ default QuicClient createQuicClient(QuicClientConfig config) {
321321
}
322322

323323
/**
324-
* Create an HTTP/HTTPS server using the specified options
324+
* Create an HTTP/HTTPS server using the specified {@code options}
325325
*
326326
* @param options the options to use
327327
* @return the server
328328
*/
329329
default HttpServer createHttpServer(HttpServerOptions options) {
330330
HttpServerConfig config = new HttpServerConfig(options);
331331
ServerSSLOptions sslOptions = options.getSslOptions();
332-
if (sslOptions != null) {
333-
sslOptions = sslOptions.copy();
334-
} else if (options.isSsl()) {
335-
sslOptions = new ServerSSLOptions();
332+
if (options.isSsl()) {
333+
if (sslOptions != null) {
334+
sslOptions = sslOptions.copy();
335+
} else if (options.isSsl()) {
336+
sslOptions = new ServerSSLOptions();
337+
}
338+
} else {
339+
sslOptions = null;
336340
}
337341
SSLEngineOptions sslEngineOptions = options.getSslEngineOptions();
338342
if (sslEngineOptions != null) {
@@ -347,7 +351,7 @@ default HttpServer createHttpServer(HttpServerOptions options) {
347351
}
348352

349353
/**
350-
* Create an HTTP server using the specified config
354+
* Create an HTTP server using the specified {@code config}.
351355
*
352356
* @param config the config to use
353357
* @return the server
@@ -357,17 +361,28 @@ default HttpServer createHttpServer(HttpServerConfig config) {
357361
}
358362

359363
/**
360-
* Create an HTTP server using the specified config
364+
* Create an HTTP server using the specified config and the specified {@code sslOptions}
361365
*
362366
* @param config the config to use
367+
* @param sslOptions the ssl options to use
363368
* @return the server
364369
*/
365370
default HttpServer createHttpServer(HttpServerConfig config, ServerSSLOptions sslOptions) {
366371
return httpServerBuilder().with(config).with(sslOptions).build();
367372
}
368373

369374
/**
370-
* Create an HTTP/HTTPS server using default options
375+
* Create an HTTP server using default config and the specified {@code sslOptions}.
376+
*
377+
* @param sslOptions the ssl options to use
378+
* @return the server
379+
*/
380+
default HttpServer createHttpServer(ServerSSLOptions sslOptions) {
381+
return httpServerBuilder().with(new HttpServerConfig()).with(sslOptions).build();
382+
}
383+
384+
/**
385+
* Create an HTTP/HTTPS server using default config.
371386
*
372387
* @return the server
373388
*/

vertx-core/src/main/java/io/vertx/core/http/HttpServerConfig.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,25 +266,6 @@ public HttpServerConfig setVersions(HttpVersion... versions) {
266266
return this;
267267
}
268268

269-
/**
270-
*
271-
* @return is SSL/TLS enabled?
272-
*/
273-
public boolean isSsl() {
274-
return tcpConfig.isSsl();
275-
}
276-
277-
/**
278-
* Set whether SSL/TLS is enabled
279-
*
280-
* @param ssl true if enabled
281-
* @return a reference to this, so the API can be used fluently
282-
*/
283-
public HttpServerConfig setSsl(boolean ssl) {
284-
tcpConfig.setSsl(ssl);
285-
return this;
286-
}
287-
288269
/**
289270
* Set the port used to bind the server at, affecting both TCP and QUIC transports.
290271
*

vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerBuilderImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ public HttpServer build() {
7777
if (useQuic && sslOptions == null) {
7878
throw new NullPointerException("SSL configuration is necessary for a QUIC server");
7979
}
80-
if (useTcp && config.isSsl() && sslOptions == null) {
81-
throw new NullPointerException("SSL configuration is necessary for a TCP/SSL server");
82-
}
8380
HttpServer server;
8481
if (useTcp) {
8582
if (useQuic) {

vertx-core/src/main/java/io/vertx/core/http/impl/tcp/TcpHttpServer.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class TcpHttpServer implements HttpServerInternal {
4747

4848
private final VertxInternal vertx;
4949
final HttpServerConfig config;
50+
private final boolean ssl;
5051
private final ServerSSLOptions sslOptions;
5152
private final SSLEngineOptions engineOptions;
5253
private final boolean registerWebSocketWriteHandlers;
@@ -66,6 +67,7 @@ public TcpHttpServer(VertxInternal vertx, HttpServerConfig config, ServerSSLOpti
6667
SSLEngineOptions engineOptions, HttpServerMetrics<?, ?> httpMetrics, boolean registerWebSocketWriteHandlers) {
6768
this.vertx = vertx;
6869
this.config = config;
70+
this.ssl = sslOptions != null;
6971
this.sslOptions = sslOptions;
7072
this.engineOptions = engineOptions;
7173
this.registerWebSocketWriteHandlers = registerWebSocketWriteHandlers;
@@ -207,7 +209,9 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
207209
}
208210
CompressionConfig compression = config.getCompressionConfig();
209211
ServerSSLOptions sslOptions = configureSSLOptions(config, this.sslOptions);
210-
NetServerInternal server = new NetServerBuilder(vertx, config.getTcpConfig(), sslOptions)
212+
TcpServerConfig tcpConfig = new TcpServerConfig(config.getTcpConfig())
213+
.setSsl(ssl);
214+
NetServerInternal server = new NetServerBuilder(vertx, tcpConfig, sslOptions)
211215
.sslEngine(engineOptions)
212216
.fileRegionEnabled(compression == null || !compression.isCompressionEnabled())
213217
.cleanable(false)
@@ -223,7 +227,7 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
223227
Supplier<ContextInternal> streamContextSupplier = context::duplicate;
224228
String host = address.isInetSocket() ? address.host() : "localhost";
225229
int port = address.port();
226-
String serverOrigin = (config.isSsl() ? "https" : "http") + "://" + host + ":" + port;
230+
String serverOrigin = (ssl ? "https" : "http") + "://" + host + ":" + port;
227231
HttpServerConnectionHandler handler = new HttpServerConnectionHandler(
228232
this,
229233
serverOrigin,
@@ -247,7 +251,7 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
247251
compressors != null && !compressors.isEmpty() && compression.isCompressionEnabled(),
248252
compressors != null && !compressors.isEmpty() && compression.isDecompressionEnabled(),
249253
observabilityConfig != null ? observabilityConfig.getTracingPolicy() : null,
250-
config.getTcpConfig().getLogConfig() != null,
254+
tcpConfig.getLogConfig() != null,
251255
compressors != null ? compressors.toArray(new CompressionOptions[0]) : null,
252256
compression != null ? compression.getContentSizeThreshold() : 0,
253257
config.isHandle100ContinueAutomatically(),
@@ -258,7 +262,7 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
258262
http2Config,
259263
registerWebSocketWriteHandlers,
260264
config.getWebSocketConfig(),
261-
config.isSsl() ? sslOptions : null,
265+
sslOptions,
262266
serverOrigin,
263267
handler,
264268
exceptionHandler,
@@ -284,7 +288,7 @@ public synchronized Future<HttpServer> listen(ContextInternal context, SocketAdd
284288
}
285289

286290
private static ServerSSLOptions configureSSLOptions(HttpServerConfig config, ServerSSLOptions sslOptions) {
287-
if (sslOptions != null && config.isSsl()) {
291+
if (sslOptions != null) {
288292
sslOptions = sslOptions.copy();
289293
boolean h2 = config.getVersions().contains(HttpVersion.HTTP_2);
290294
if (h2) {

vertx-core/src/test/java/io/vertx/tests/http/CompositeHttpServerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public void testFailTcp() throws Exception {
5353

5454
public void expectFail() {
5555
HttpServerConfig config = new HttpServerConfig()
56-
.setSsl(true)
5756
.setPort(4043)
5857
.setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_3);
5958
HttpServer server = vertx.createHttpServer(config, new ServerSSLOptions().setKeyCertOptions(Cert.SERVER_JKS.get()));
@@ -71,7 +70,6 @@ public void expectSucceed() throws Exception {
7170

7271
public void expectSucceed(Vertx vertx) throws Exception {
7372
HttpServerConfig config = new HttpServerConfig()
74-
.setSsl(true)
7573
.setPort(4043)
7674
.setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_3);
7775

@@ -103,7 +101,6 @@ public void expectSucceed(Vertx vertx) throws Exception {
103101
public void testAutomaticCleanup() {
104102

105103
HttpServerConfig config = new HttpServerConfig()
106-
.setSsl(true)
107104
.setPort(4043)
108105
.setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_3);
109106

vertx-core/src/test/java/io/vertx/tests/http/SupportedVersionsTest.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,27 +210,27 @@ public void testHttp2ServerConfig() {
210210
@Test
211211
public void testDefaultTlsServerConfig() {
212212
test(
213-
new HttpServerConfig().setSsl(true),
213+
new HttpServerConfig(),
214214
new HttpClientConfig().setSsl(true),
215215
HttpVersion.HTTP_2,
216216
null, HttpVersion.HTTP_1_1, HttpVersion.HTTP_2);
217217
test(
218-
new HttpServerConfig().setSsl(true),
218+
new HttpServerConfig(),
219219
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_2),
220220
HttpVersion.HTTP_2,
221221
null, HttpVersion.HTTP_1_1, HttpVersion.HTTP_2);
222222
test(
223-
new HttpServerConfig().setSsl(true),
223+
new HttpServerConfig(),
224224
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_2, HttpVersion.HTTP_1_1),
225225
HttpVersion.HTTP_2,
226226
null, HttpVersion.HTTP_1_1, HttpVersion.HTTP_2);
227227
test(
228-
new HttpServerConfig().setSsl(true),
228+
new HttpServerConfig(),
229229
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
230230
HttpVersion.HTTP_2,
231231
null, null, HttpVersion.HTTP_2);
232232
test(
233-
new HttpServerConfig().setSsl(true),
233+
new HttpServerConfig(),
234234
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
235235
HttpVersion.HTTP_1_1,
236236
null, HttpVersion.HTTP_1_1, null);
@@ -239,27 +239,27 @@ public void testDefaultTlsServerConfig() {
239239
@Test
240240
public void testHttp1TlsServerConfig() {
241241
test(
242-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
242+
new HttpServerConfig().setVersions(HttpVersion.HTTP_1_1),
243243
new HttpClientConfig().setSsl(true),
244244
HttpVersion.HTTP_1_1,
245245
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1);
246246
test(
247-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
247+
new HttpServerConfig().setVersions(HttpVersion.HTTP_1_1),
248248
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_2),
249249
HttpVersion.HTTP_1_1,
250250
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1);
251251
test(
252-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
252+
new HttpServerConfig().setVersions(HttpVersion.HTTP_1_1),
253253
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_2, HttpVersion.HTTP_1_1),
254254
HttpVersion.HTTP_1_1,
255255
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1);
256256
test(
257-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
257+
new HttpServerConfig().setVersions(HttpVersion.HTTP_1_1),
258258
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
259259
null,
260260
null, null, null);
261261
test(
262-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
262+
new HttpServerConfig().setVersions(HttpVersion.HTTP_1_1),
263263
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
264264
HttpVersion.HTTP_1_1,
265265
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1, null);
@@ -268,27 +268,27 @@ public void testHttp1TlsServerConfig() {
268268
@Test
269269
public void testHttp2TlsServerConfig() {
270270
test(
271-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
271+
new HttpServerConfig().setVersions(HttpVersion.HTTP_2),
272272
new HttpClientConfig().setSsl(true),
273273
HttpVersion.HTTP_2,
274274
null, null, HttpVersion.HTTP_2);
275275
test(
276-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
276+
new HttpServerConfig().setVersions(HttpVersion.HTTP_2),
277277
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1, HttpVersion.HTTP_2),
278278
HttpVersion.HTTP_2,
279279
null, null, HttpVersion.HTTP_2);
280280
test(
281-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
281+
new HttpServerConfig().setVersions(HttpVersion.HTTP_2),
282282
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_2, HttpVersion.HTTP_1_1),
283283
HttpVersion.HTTP_2,
284284
null, null, HttpVersion.HTTP_2);
285285
test(
286-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
286+
new HttpServerConfig().setVersions(HttpVersion.HTTP_2),
287287
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
288288
HttpVersion.HTTP_2,
289289
null, null, HttpVersion.HTTP_2);
290290
test(
291-
new HttpServerConfig().setSsl(true).setVersions(HttpVersion.HTTP_2),
291+
new HttpServerConfig().setVersions(HttpVersion.HTTP_2),
292292
new HttpClientConfig().setSsl(true).setVersions(HttpVersion.HTTP_1_1),
293293
null,
294294
null, null, null);
@@ -338,7 +338,13 @@ private void test(HttpServerConfig server, HttpClientConfig client, boolean useA
338338

339339
private HttpVersion testDefaultVersion(HttpServerConfig serverConfig, HttpClientConfig clientConfig, boolean useAlpn) {
340340
return testDefaultVersion(
341-
() -> vertx.createHttpServer(serverConfig, useAlpn ? DEFAULT_SERVER_TLS : DEFAULT_SERVER_TLS_NO_ALPN),
341+
() -> {
342+
if (clientConfig.isSsl()) {
343+
return vertx.createHttpServer(serverConfig, useAlpn ? DEFAULT_SERVER_TLS : DEFAULT_SERVER_TLS_NO_ALPN);
344+
} else {
345+
return vertx.createHttpServer(serverConfig);
346+
}
347+
},
342348
() -> vertx.createHttpClient(clientConfig, DEFAULT_CLIENT_TLS)
343349
);
344350
}

0 commit comments

Comments
 (0)