Skip to content

Commit 70e7216

Browse files
authored
Use Http2SslContextSpec to build SslContext when http2 enabled (#2764)
1 parent 10c127a commit 70e7216

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

reactor-netty-examples/src/main/java/reactor/netty/examples/http/echo/EchoServer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2021 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2020-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import io.netty.handler.ssl.util.SelfSignedCertificate;
1919
import reactor.netty.http.Http11SslContextSpec;
20+
import reactor.netty.http.Http2SslContextSpec;
2021
import reactor.netty.http.HttpProtocol;
2122
import reactor.netty.http.server.HttpServer;
2223

@@ -48,8 +49,12 @@ public static void main(String[] args) throws Exception {
4849

4950
if (SECURE) {
5051
SelfSignedCertificate ssc = new SelfSignedCertificate();
51-
server = server.secure(
52-
spec -> spec.sslContext(Http11SslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
52+
if (HTTP2) {
53+
server = server.secure(spec -> spec.sslContext(Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
54+
}
55+
else {
56+
server = server.secure(spec -> spec.sslContext(Http11SslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
57+
}
5358
}
5459

5560
if (HTTP2) {

reactor-netty-examples/src/main/java/reactor/netty/examples/http/helloworld/HelloWorldServer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2021 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2020-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
import io.netty.handler.ssl.util.SelfSignedCertificate;
1919
import reactor.core.publisher.Mono;
2020
import reactor.netty.http.Http11SslContextSpec;
21+
import reactor.netty.http.Http2SslContextSpec;
2122
import reactor.netty.http.HttpProtocol;
2223
import reactor.netty.http.server.HttpServer;
2324

@@ -49,8 +50,12 @@ public static void main(String[] args) throws Exception {
4950

5051
if (SECURE) {
5152
SelfSignedCertificate ssc = new SelfSignedCertificate();
52-
server = server.secure(
53-
spec -> spec.sslContext(Http11SslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
53+
if (HTTP2) {
54+
server = server.secure(spec -> spec.sslContext(Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
55+
}
56+
else {
57+
server = server.secure(spec -> spec.sslContext(Http11SslContextSpec.forServer(ssc.certificate(), ssc.privateKey())));
58+
}
5459
}
5560

5661
if (HTTP2) {

0 commit comments

Comments
 (0)