Quality Outreach Heads-up - JDK 26: HTTP/3 Support Available in HTTP Client API

The OpenJDK Quality Group is promoting the testing of FOSS projects with OpenJDK builds as a way to improve the overall quality of the release. This heads-up is part of the quality outreach sent to the projects involved. To learn more about the program, and how-to join, please check here.

HTTP/3 Support in HttpClient

The java.net.http.HttpClient API allows Java applications to create reusable HTTP client instances, build HTTP requests, and handle responses synchronously or asynchronously. Since JDK 11, you can set the preferred HTTP protocol versions like HTTP/1.1 or HTTP/2 at the HttpClient or HttpRequest level.

JEP 517 introduces support for HTTP/3 (HttpClient.Version.HTTP_3) in JDK 26, enabling applications to prefer or enforce HTTP/3 for requests. While HTTP/3 offers similar features to HTTP/2 at the protocol level, its key difference is that it runs over the QUIC protocol using UDP, whereas HTTP/2 operates over TCP. Below is a code snippet on how you can prefer and/or enforce HTTP/3:

// prefer HTTP/3
HttpClient client = HttpClient.newBuilder()
    .version(HttpClient.Version.HTTP_3)
    .build();

// if target server support HTTP/3, add this to enforce it
HttpRequest req = HttpRequest.newBuilder()
    .uri(new URI("https://www.google.com/"))
    .setOption(HttpOption.H3_DISCOVERY, Http3DiscoveryMode.HTTP_3_URI_ONLY)
    .build();

HttpResponse<String> resp = client.send(req, BodyHandlers.ofString(StandardCharsets.UTF_8));
System.out.println("status code: " + resp.statusCode() + " HTTP protocol version: " + resp.version());

If you set HTTP/3 but it is not available, the client will automatically downgrade to HTTP/2 or HTTP/1.1. If you configure to strictly require HTTP/3, a failed attempt leads to an exception rather than a downgrade.

However, setting HTTP/3 as the preferred version does not guarantee its use, as the client cannot know beforehand if the server supports it. For the first request to a server, the client tries both TCP (HTTP/2) and UDP (HTTP/3) connections and uses whichever succeeds first. Over time, the HttpClient can “learn” about the HTTP version(s) that a server supports by using the “Alt-Svc” mechanism (the “HTTP Alternative Services” standard per RFC 7838). Servers supporting “Alt-Svc” advertise alternative supported protocols such as HTTP/3. This allows subsequent requests to that server to use HTTP/3 when supported. For more details on this mechanism, see this article.

Call to Action

Although the enhancements to the HTTP Client API appear simple to use, supporting HTTP/3 on top of QUIC represents the result of several years of dedicated development effort within the JDK team. As this implementation is still new, we encourage you to download the Java 26 Early Access builds, try this feature, and share your feedback through the net-dev OpenJDK mailing list (registration required).

~