Skip to content

Commit

Permalink
Initial HTTP/3 client support (#3319)
Browse files Browse the repository at this point in the history
Related to #1531
  • Loading branch information
violetagg committed Jun 27, 2024
1 parent 0d782d9 commit 3c3297f
Show file tree
Hide file tree
Showing 14 changed files with 1,568 additions and 41 deletions.
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

0 comments on commit 3c3297f

Please sign in to comment.