Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HttpProtocol#HTTP3 #3161

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2018-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,5 +48,11 @@ public enum HttpProtocol {
* require {@literal Connection: Upgrade} handshake between a client and server but
* fallback to HTTP/1.1 will not be supported.
*/
H2C
H2C,

/**
* HTTP/3.0 support.
* @since 1.2.0
*/
HTTP3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reactor.netty.http.internal;

/**
* Utility class around HTTP/3.
* <p><strong>Note:</strong> This utility class is for internal use only. It can be removed at any time.
*
* @author Violeta Georgieva
* @since 1.2.0
*/
public final class Http3 {

static final boolean isHttp3Available;
static {
boolean http3;
try {
Class.forName("io.netty.incubator.codec.http3.Http3");
http3 = true;
}
catch (Throwable t) {
http3 = false;
}
isHttp3Available = http3;
}

/**
* Check if the current runtime supports HTTP/3, by verifying if {@code netty-incubator-codec-http3} is on the classpath.
*
* @return true if {@code netty-incubator-codec-http3} is available
*/
public static boolean isHttp3Available() {
return isHttp3Available;
}

private Http3() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import reactor.util.context.Context;

import static reactor.netty.ReactorNetty.format;
import static reactor.netty.http.internal.Http3.isHttp3Available;
import static reactor.netty.http.server.HttpServerConfig.h3;

/**
* An HttpServer allows building in a safe immutable way an HTTP server that is
Expand Down Expand Up @@ -836,6 +838,11 @@ public final HttpServer protocol(HttpProtocol... supportedProtocols) {
Objects.requireNonNull(supportedProtocols, "supportedProtocols");
HttpServer dup = duplicate();
dup.configuration().protocols(supportedProtocols);
if ((dup.configuration()._protocols & h3) == h3 && !isHttp3Available()) {
throw new UnsupportedOperationException(
"To enable HTTP/3 support, you must add the dependency `io.netty.incubator:netty-incubator-codec-http3`" +
" to the class path first");
}
return dup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public Mono<? extends DisposableServer> bind() {
"Use a Clear-Text H2 protocol via HttpServer#protocol or configure TLS " +
"via HttpServer#secure"));
}
else if ((config._protocols & HttpServerConfig.h3) == HttpServerConfig.h3) {
return Mono.error(new IllegalArgumentException(
"Configured H3 protocol without TLS. Configure TLS via HttpServer#secure"));
}
}
return super.bind();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ else if (p == HttpProtocol.H2) {
else if (p == HttpProtocol.H2C) {
_protocols |= h2c;
}
else if (p == HttpProtocol.HTTP3) {
_protocols |= h3;
}
}
this._protocols = _protocols;
}
Expand Down Expand Up @@ -796,6 +799,8 @@ else if (metricsRecorder instanceof ContextAwareHttpServerMetricsRecorder) {

static final boolean ACCESS_LOG = Boolean.parseBoolean(System.getProperty(ACCESS_LOG_ENABLED, "false"));

static final int h3 = 0b1000;

static final int h2 = 0b010;

static final int h2c = 0b001;
Expand Down
Loading