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

Initial HTTP/3 client support #3319

Merged
merged 1 commit into from
Jun 27, 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
15 changes: 15 additions & 0 deletions docs/modules/ROOT/pages/http-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ include::{examples-dir}/http2/H2CApplication.java[lines=18..41]
include::{sourcedir}/reactor/netty/http/HttpProtocol.java[lines=24..58]
----

[[HTTP3]]
== HTTP/3
By default, the `HTTP` client supports `HTTP/1.1`. If you need `HTTP/3`, you can get it through configuration.
In addition to the protocol configuration, you need to add dependency to `io.netty.incubator:netty-incubator-codec-http3`.

The following listing presents a simple `HTTP3` example:

{examples-link}/http3/Application.java
----
include::{examples-dir}/http3/Application.java[lines=18..49]
----
<1> Configures the client to support only `HTTP/3`
<2> Configures `SSL`
<3> Configures `HTTP/3` settings

include::partial$proxy.adoc[]

[[metrics]]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.examples.documentation.http.client.http3;

import io.netty.handler.codec.http.HttpHeaders;
import reactor.core.publisher.Mono;
import reactor.netty.http.HttpProtocol;
import reactor.netty.http.client.HttpClient;
import reactor.util.function.Tuple2;

import java.net.InetSocketAddress;
import java.time.Duration;

public class Application {

public static void main(String[] args) throws Exception {
HttpClient client =
HttpClient.create()
.remoteAddress(() -> new InetSocketAddress("www.google.com", 443))
.protocol(HttpProtocol.HTTP3) //<1>
.secure() //<2>
.http3Settings(spec -> spec.idleTimeout(Duration.ofSeconds(5)) //<3>
.maxData(10000000)
.maxStreamDataBidirectionalLocal(1000000));

Tuple2<String, HttpHeaders> response =
client.get()
.uri("/")
.responseSingle((res, bytes) -> bytes.asString()
.zipWith(Mono.just(res.responseHeaders())))
.block();

System.out.println("Used stream ID: " + response.getT2().get("x-http3-stream-id"));
System.out.println("Response: " + response.getT1());
}
}
Loading